Make a PreparedScriptBenchmark class closer to the original by Taritsyn · Pull Request #2325 · sebastienros/jint (original) (raw)

Hello!

Main difference between the PreparedScriptBenchmark class and the original one is that the script is pre-compiled in the Setup method and is therefore not taken into account when measuring performance.

Initial version of the PreparedScriptBenchmark class shows very good result:

| Method                           | Mean      | Error    | StdDev   | Median    | Ratio | RatioSD | Gen0      | Gen1      | Allocated | Alloc Ratio |
|--------------------------------- |----------:|---------:|---------:|----------:|------:|--------:|----------:|----------:|----------:|------------:|
| ExecuteStringOnMultipleEngines   | 195.27 ms | 3.767 ms | 4.898 ms | 194.13 ms |  1.00 |    0.03 | 5000.0000 | 2000.0000 |   34.1 MB |        1.00 |
| ExecutePreparedOnMultipleEngines |  98.61 ms | 1.966 ms | 5.610 ms |  96.88 ms |  0.51 |    0.03 | 3000.0000 | 1000.0000 |  18.94 MB |        0.56 |

Version with my edits shows a result close to the original:

| Method                           | Mean     | Error   | StdDev   | Ratio | RatioSD | Gen0      | Gen1      | Allocated | Alloc Ratio |
|--------------------------------- |---------:|--------:|---------:|------:|--------:|----------:|----------:|----------:|------------:|
| ExecuteStringOnMultipleEngines   | 197.0 ms | 3.94 ms |  4.21 ms |  1.00 |    0.03 | 5000.0000 | 2000.0000 |   34.1 MB |        1.00 |
| ExecutePreparedOnMultipleEngines | 254.5 ms | 5.08 ms | 10.37 ms |  1.29 |    0.06 | 3000.0000 | 1000.0000 |  23.58 MB |        0.69 |

Perhaps this is due to the fact that every time the Engine.PrepareScript method is called, then a new instance of the Parser class is created.