Which .NET JavaScript Engine is the fastest?

UPDATE 6/17/2015: Added NiL.JS, updated to the latest version of ClearScript and Jint, fixed ClearScript “compiled” test, and updated results for all.

UPDATE 6/18/2015:Reran with more tests

In RulePlex users are allowed to write rules in JavaScript, make an API call which passes in data, and execute those rules in the cloud. RulePlex is written in .NET. So how do we execute JavaScript in .NET? It turns out there are a bunch of JavaScript engines that can do this, but which one is the fastest?

I took an inventory of the more popular .NET JavaScript engines:

My initial thoughts were that JavaScript.Net would be fast since it is just a wrapper for Google’s V8 engine which is the fastest JavaScript engine currently. I also thought IronJS would be fast since it uses Microsoft’s Dynamic Language Runtime. jint and Jurassic I was skeptical about.

The Tests

I created a project and referenced each engine by using NuGet. I called each engine 5 times to execute a snippet of code and took the average. The snippet of code I executed came from a suite of array tests I found at Dromaeo. You can view the tests in this gist.

I also did another test where I loaded the linq.js library (one of my favorite, lesser known, JavaScript libraries) but I ran it 50 times.

The Results

Array test results:

jint14,028 ms
IronJS1,622 ms
JavaScript.Net20 ms
Jurassic237 ms
ClearScript263 ms
ClearScript (compiled)111 ms
NiL.JS1,680 ms
Linq.js load results:

jint17 ms
IronJS176 ms
JavaScript.Net13 ms
Jurassic114 ms
ClearScript37 ms
ClearScript (compiled)22 ms
NiL.JS17 ms
If you come across any other .NET JavaScript engines feel free to let me know and I’ll add them to my comparison.

One More Test

I wasn’t entirely happy with the tests I had done so I added one more. The script I executed only does one small thing – set a variable to true. This shows more or less the overhead of each engine. I ran this this test 5000 times each and took the average.

One variable results:

jint<1 ms
IronJS<1 ms
JavaScript.Net9 ms
Jurassic3 ms
ClearScript31 ms
ClearScript (compiled)22 ms
NiL.JS<1 ms
Here is the complete script I used. I swapped out currentScript and changed N as needed.

Target Framework was .NET 4.5.1, Target Platform was x86. Run on a quad score i7 CPU @ 2.40 GHz.

Updated Results 6/17/2015:

  • Jint does well with small scripts. Has become faster since last August.
  • IronJS did okay
  • JavaScript.Net looks like it is the overall fastest
  • Jurassic did pretty good
  • ClearScript is fast but has a lot of overhead. Might want to try ClearScript.Manager to help with this. (Even so, I’ve had problems getting it to scale.)
  • NiL.JS did okay