IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New *All* arrays in PHP are hashes
The only difference between my code and Wade's was how we checked for the existence: in_array vs. isset. And without benchmarking, I don't know enough about the internal implementation to know which is better. Interesting to see it's an order of magnitude difference.
--

Drew
New Big difference
Here:

http://brian.moonspo...ay-is-quite-slow/

But it only matter when you are trying to do large lookups - which I am.
My lookup tables are about 20,000 entries long, and I have 6 of them. Their key size varies from 2 characters to 50 characters, with the vast majority between 12 and 35 characters.

New Multiple orders of magnitude difference
is_set will do a hash calculation bucket lookup, and then possibly a chain walk via a linked list if your keys hash too close together. It's a pretty constant access time, no matter how large your list gets.

If I'm coding in Perl, it is a choice to use it. It takes a bit longer to construct and load a hash list though, so I don't use it by the default if I don't need it, and instead want standard array access (queuing, push, pop, numeric access, etc).

I understand that it is not an option in PHP, hashes are simply used. It simply depends on what method of access you use.

I ASSUME in_array has to access the first item, compare it, access the next item, compare it, read the next item, compare it.

But the time you've gotten to the 3rd compare (or so, no I haven't timed this), a hashed lookup would be complete.

So how many orders of magnitude is it if is is a 20,000 item lookup table, which would mean (assuming that 3 record walk vs hash access time holds) it is 6,666 times faster.
New It's an index vs. value thing.
array_key_exists() and isset() both look at the array's key, which *is* the hash-table lookup. It's wicked fast: probably the fastest thing you can do with an array in PHP.

in_array() looks in the array's *values*. These are *not* in a hash-table and is therefore much much much slower.

Wade, who is paid to know this stuff.

Q:Is it proper to eat cheeseburgers with your fingers?
A:No, the fingers should be eaten separately.
New Ahh, but look at my corrected* version
You're checking if the array key exists in the second dimension of the array. I'm checking for the value in the first dimension. Both versions are looking at the same hash.


* I had the parameters reversed until I just now updated it.
--

Drew
New Why is this an argument?
in_array == bad for large sets.
Dead end on this path.
New Because I didn't read all the comments on that thread
Which I now have. So I now understand that the keys are indexed, but the values are not.
--

Drew
New Good
I love educational threads.
New Thank you...
Sister Barry Catherine.

Please no rulers today!
New I prefer the gentle approach
Like my daughter says to me all the time:

GET OUT OF MY HEAD!

I never tell her what to do or think. But little anecdotes and hints are enough to send the wheels spinning. She hates that.
     PHP vs Perl questions - (crazy) - (17)
         Ooops, - (crazy)
         Try this - (drook) - (15)
             Here's a better version. - (static) - (14)
                 Why better? - (drook) - (13)
                     Well, it depends on what defined() means in PERL. - (static) - (12)
                         So two issues - (drook) - (11)
                             That's the problem - (crazy) - (10)
                                 *All* arrays in PHP are hashes - (drook) - (9)
                                     Big difference - (crazy)
                                     Multiple orders of magnitude difference - (crazy) - (7)
                                         It's an index vs. value thing. - (static) - (6)
                                             Ahh, but look at my corrected* version - (drook) - (5)
                                                 Why is this an argument? - (crazy) - (4)
                                                     Because I didn't read all the comments on that thread - (drook) - (3)
                                                         Good - (crazy) - (2)
                                                             Thank you... - (folkert) - (1)
                                                                 I prefer the gentle approach - (crazy)

Otherwise there are Deliverance theme parks.
72 ms