Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Benchmarks

0
0
Heh, it looks like we were investigating simultaneously :)

It is generating a new name even the same script is being executed twice.

Right. When you call a method that takes the code as a string, ClearScript considers it a new script. It doesn't cache the code for subsequent lookup, deferring to the underlying script engine for that sort of optimization. It might benefit from doing what you suggest, but the code cache could also explode under some usage patterns.

By the way, the unique script name is just metadata that shows up in script debuggers; it doesn't affect script execution. JavaScript.NET doesn't bother with script names at all, probably because it doesn't support script debugging.

If the same script is being executed twice, it will run extremely fast and efficient (Should have the same performance as compiling the script).

If that's how it works, then V8 does it all under the covers. Neither ClearScript nor JavaScript.NET look up previously compiled scripts. When given a code string to execute, they both call V8's compilation method and then its execution method.

I think Javascript.NET has similar optimization because the first code below runs almost 8~10x slower than the second one

It's possible that V8 does what you suggest behind the scenes, but it could also be that V8 optimizes "Math.random()" completely away when it detects that your script doesn't use the return value.

Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images