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

New Post: Benchmarks

0
0
What is GlobalMembers support?

When I ran the test below, I only see a small performance increase after disabling global members. Also, I compared it with Javascript.NET and the differences is huge. But if I compiled the script before running it, it is almost 2~3X of Javascript.NET. (Our application needs to update hundreds if not thousands of items when a property is modified, so measuring performance like this is very important)

Script is "Math.random();"

Clearscript in 942
Clearscript with DisableGlobalMembers in 930
Javascript.NET in 21

//After compiled
Clearscript in 57
Clearscript with DisableGlobalMembers in 53
Javascript.NET in 27
public static void TestClear(string script, bool disableGlobal)
{
    var engine = new V8ScriptEngine(disableGlobal ? V8ScriptEngineFlags.DisableGlobalMembers : V8ScriptEngineFlags.None);
    
    var sw = new Stopwatch();
    sw.Start();

    //var compiled = engine.Compile(script);

    for (int i = 0; i < 10000; i++)
    {
        //engine.Evaluate(compiled);
        engine.Evaluate(script);
    }

    sw.Stop();
    Console.WriteLine("Clearscript" + (disableGlobal ? " with DisableGlobalMembers" : "") + " in " + sw.ElapsedMilliseconds);
}

Viewing all articles
Browse latest Browse all 2297