For a project I am working on, I have a list of words that needs to be in an array. There are a lot of words (about 20,000 split across 3 arrays). I thought it would be faster to serialize the array and store it in another file and unserialize it when I needed it. This worked, but was difficult to update. An explode is much easier to update, but is it more efficient?

…and the winner is (to my surprise) Explode.
Update: Added Memory usage.
Update 2: Added json_decode();

Explode took 1.78813934326E-5 Seconds
Explode used 744 b of memory

Unserialize took 0.000228881835938 Seconds
Unserialize used 71.79 kb of memory

JSON Decode took 0.00021505355835 Seconds
JSON Decode used 76.73 kb of memory

Here is what I used to test.

3 Comments

  1. Andrew Buckman

    Nice job actually testing instead of assuming! I’d have guessed explode personally, just looking at serialized data it looks more complicated to unwrap. Obviously there are times when it’s more appropriate.

    1. David

      I’m supprised, json_decode basically takes the same amount of time but uses more memory. I thought it would have been faster as there’s less to parse through (compared to unserialize).

Leave a Reply

Your email address will not be published. Required fields are marked *