Another thing Zend_Json does that json_encode() does not is supporting
iterable objects. I use this frequently for JSON encoding objects that do
not have public properties.

p.s. I think that Zend_Json should actually check for the objects
implementing Traversable (http://us.php.net/manual/en/class.traversable.php),
not Iterator (http://us.php.net/manual/en/class.iterator.php), since all the
encoder is doing is foreach'ing over the object, but that's for another bug
report.

Konr

On Fri, Dec 10, 2010 at 11:38 AM, Matthew Weier O'Phinney
<[email protected]>wrote:

> Yes, Zend_Json is slower than ext/json, even when it proxies directly to
> ext/json. That said, there are a number of situations where you might
> wish to use Zend_Json over ext/json:
>
>  * If you have to encode JS lambdas as JSON
>  * If you want support for additional charset encodings
>
> Finally, for most datasets developers will utilize, the amount of time
> spent in de/serialization is negligible -- if you're working on datasets
> of 100k+ items, you're likely doing something wrong anyways.
>
> -- whisher <[email protected]> wrote
> (on Friday, 10 December 2010, 08:44 AM -0800):
> >
> > $memoryNativeStart = memory_get_peak_usage (true);
> >
> > $start = microtime( true );
> >
> > $native = json_decode(json_encode( $data ));
> >
> > $memoryNative = memory_get_peak_usage (true) - $memoryNativeStart;
> >
> > $jsonNativeTime = microtime( true ) - $start;
> >
> > $msgNative = 'Native php
> > ';
> >
> > $msgNative .= 'time '.$jsonNativeTime.' memory '.$memoryNative.'
> > ';
> >
> > echo $msgNative;
> >
> > sleep(3);
> >
> > $memoryZendStart = memory_get_peak_usage (true);
> >
> > $start = microtime( true );
> >
> > $zend = Zend_Json::decode(Zend_Json::encode( $data ));
> >
> > $memoryZend = memory_get_peak_usage (true) - $memoryZendStart;
> >
> > $jsonZendTime = microtime( true ) - $start;
> >
> > $msgZend = 'Zend
> > ';
> >
> > $msgZend .= 'time '.$jsonZendTime.' memory '.$memoryZend;
> >
> > echo $msgZend;
> >
> > inside data there is about 130,000 records (with a result set)
> >
> > I get
> >
> > Native php
> >
> > time 2.24236011505 memory 158072832
> >
> > Zend
> >
> > time 3.50552582741 memory 109051904
> > --
> > View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/json-encode-json-decode-vs-Zend-Json-encode-Zend-Json-decode-tp3080647p3082295.html
> > Sent from the Zend Framework mailing list archive at Nabble.com.
> >
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [email protected]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>

Reply via email to