Breakfast: json_encode vs serialize 
 Souls non-technical, go your way ... 
 
 Quite simply, for site development  of Kappa  I needed a comparison between the functions  json_encode ()   and serialize ()  PHP 5.2 
 Both approaches can transform the variables into a string, and JSON     and used extensively for some time to trade Ajax, because it is implemented in different languages (unlike  serialize ()  which is only for PHP). 
 
 For me the point is to serialize an array to store the value in a cookie. Now the function  serialize ()  me back a string that is about 40% more  Long  than  json_encode () . The saving in space is precious to me, because a cookie has a size limit (about 4000 characters). But do not think it saves space has a significant cost of time. 
 So I made a small benchmark that does not pretend to be universal, on my personal machine with Ubuntu 6.10, and I noticed that  json_encode ()  takes about ...  40% more time than   serialize () . 
 However, the difference is still not huge, since in my case this is equivalent to 2.5 millionths of a second   more. I know I'm a maniac of optimization but I think I'm going to meet that. 
 
 Anyway, as I did not find any comparison between these two functions, I shall (if that can be used for other ...)  
0 comments:
Post a Comment