As exception to confirm the rule, sfari 4 beta average is 1 second of non-sense via function against about 100ms via eval ...
On May 20, 2009 11:48 AM, "Andrea Giammarchi" <andrea.giammar...@gmail.com> wrote: Ok, the reason eval is so slow is because of FireBug, it costed 17 seconds with FireBug enabled while FireBug seems to do not affect Function execution (which makes Function against better than eval). In any case, Function is faster or exactly fast as eval is, even in Internet Explorer, at least in my tests. this is a truly simple readapted test case: <!DOCTYPE html> <script type="text/javascript"> portable = (function(msg, i, interval){ function timeout(){ alert(msg.join("\n")); msg = []; i = 0; }; return { log:function(test){ msg[i++] = test; clearTimeout(interval); interval = setTimeout(timeout, 100); } } })([], 0, 0); var count = 10000, o = null, i = 0, jsonString = '{"value":{"items":[{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3}]},"error":null}'; var beginTime = new Date(); for ( i = 0; i < count; i++ ) o = eval( "(" + jsonString + ")" ); portable.log( "eval:" + ( new Date() - beginTime ) ); var beginTime = new Date(); for ( i = 0; i < count; i++ ) o = new Function( "return " + jsonString )(); portable.log( "new Function:" + ( new Date() - beginTime ) ); var beginTime = new Date(); for ( i = 0; i < count; i++ ) o = Function( "return " + jsonString )(); portable.log( "Function:" + ( new Date() - beginTime ) ); var beginTime = new Date(); var callback = Function( "return " + jsonString ); for ( i = 0; i < count; i++ ) o = callback(); portable.log( "precompiled Function:" + ( new Date() - beginTime ) ); if(this.JSON){ var beginTime = new Date(); for ( i = 0; i < count; i++ ) o = JSON.parse(jsonString); portable.log( "native:" + ( new Date() - beginTime ) ); }; </script> Let me know what you think. Regards On Wed, May 20, 2009 at 7:43 AM, Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > > As ... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---