Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context.Execute is slower than Context.ExecuteFile #84

Open
cheranm opened this issue Jul 28, 2011 · 1 comment
Open

Context.Execute is slower than Context.ExecuteFile #84

cheranm opened this issue Jul 28, 2011 · 1 comment

Comments

@cheranm
Copy link

cheranm commented Jul 28, 2011

I am using the below C# code snippet to measure the performance of simple java script expression execution.

        int COUNT = 10000;
        // Do a timing test, across many iterations, for an expression
        object result1 = null;
    var ctx = new CSharp.Context();
        DateTime begin = DateTime.Now;
        for (int i = 0; i < COUNT; i++)
        {
            result1 = ctx.Execute("3 * 20;");
        }

        DateTime end = DateTime.Now;
        TimeSpan x = new TimeSpan(end.Ticks - begin.Ticks);
        Console.WriteLine("Expression: Number of seconds for " + COUNT + " expressions: " + x.TotalSeconds);

It took 143 seconds to run 10,000 iterations. At the same time if put the same expression into a file and call ctx.ExecuteFile("C:\test.js") and it took only 600 ms. Any thoughts or suggestions is helpful.

@asbjornu
Copy link
Collaborator

asbjornu commented Aug 4, 2011

I haven't looked at the Execute() or ExecuteFile() source code, but perhaps ExecuteFile() caches the AST tree for the parsed test.js file and uses the cache on each execution while with Execute there is no caching mechanism? It should be possible to just do a simple SHA1 of the code within Execute() and use that as a key for the cache.

Unless I've got it all wrong and there is no cache involved, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants