Skip to content

Speed optimization #757

@matejicko

Description

@matejicko

Hello, I am new with dotnet-script and my goal is to make small API testing framework, which will take .csx files as pre-request and/or post-response scripts.

One of the main goals is to make this FW as fast as possible so that multiple scripts (in tens to hundreds) can be run in a reasonable amount of time. I have tried to run your CLI commands by using Process and it was quite slow for my needs (mean time around 880 ms). Therefore, I have changed approach and used Dotnet.Script.Core as NuGet and tried to run the script programatically.

My code looks like this so far:

var code = await File.ReadAllTextAsync(filename);

var stop = new Stopwatch();
var logFactory = LogHelper.CreateLogFactory("release");
ExecuteCodeCommandOptions options =
    new(code, Environment.CurrentDirectory, [], OptimizationLevel.Release, true, []);

stop.Start();
var ret = await new ExecuteCodeCommand(ScriptConsole.Default, logFactory).Execute<int>(options);
stop.Stop();

Unfortunately, when I did experiment with 100 runs, it went even worse, where execution of one basic-script.csx lasted around 1 550 ms.

// basic-script.csx
Console.WriteLine("Hello world");

Therefore, I would like to ask you, how can I run scripts in more optimalised way - if there is some configuration/options, that can be used, or if I should re-write my code completely? Maybe also, if there is possibility to pre-compile scripts somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions