Skip to content

First call of Quantity.From is extremely slow compared to subsequent calls #965

Closed
@id0001

Description

@id0001

As stated in the title the first call to Quantity.From is noticeably slow, which impacts the user experience when used for a textbox.

To reproduce I basically run the following code:

Stopwatch sw = Stopwatch.StartNew();
Ratio v = (Ratio)Quantity.From(50, RatioUnit.Percent);   
sw.Stop();   
Console.WriteLine($"Time: {sw.Elapsed.TotalMilliseconds}");   

Result:

Time: 1204.4786ms
Time: 0.0041ms
Time: 0.0029ms
Time: 0.0022ms
Time: 0.0011ms
Time: 0.002ms
Time: 0.002ms
Time: 0.0021ms
Time: 0.0015ms
Time: 0.0019ms
Time: 0.0022ms
Time: 0.0015ms
Time: 0.0026ms
Time: 0.0017ms
Time: 0.0011ms
Time: 0.0021ms
Time: 0.0014ms

It's only the first call to Quantity.From(). Doesn't matter which unit and changing units after does not produce longer times.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions