6

I don't get it, the data produced by json_encode is much more straightforward than serialize and yet both the JSON encode and decode functions are much more slower than the serialize and unserialize counterparts. Why?

robjmills
  • 18,438
  • 15
  • 77
  • 121
Alix Axel
  • 151,645
  • 95
  • 393
  • 500

1 Answers1

14

json_encode does string parsing and tons of allocs compared to serialize's memcpy

Have fun in the source if you're really in the mood.

tristanbailey
  • 4,427
  • 1
  • 26
  • 30
Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213
  • So does that make JSON safer for multi-byte strings? – Xeoncross Dec 07 '10 at 04:25
  • Looks like the source for [json_encode](https://github.com/php/php-src/blob/master/ext/json/json_encoder.c) vs [serialize](https://github.com/php/php-src/blob/master/ext/standard/var.c) Looks tidy code but I can't read C well ! – tristanbailey Feb 13 '21 at 14:10