Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jhonabreul
Copy link
Collaborator

@jhonabreul jhonabreul commented Aug 13, 2025

Refactor enums comparison operators for performance improvements.
Introduce new EnumObject class to handle managed enums and their comparison operations.

Performance test:

public void PerformanceTest()
{
    using var _ = Py.GIL();
    using var module = PyModule.FromString("PerformanceTest", $@"
from System import DayOfWeek

def test():
    result = True
    enum_value = DayOfWeek.MONDAY
    for _ in range(500000):
        result = result and enum_value == DayOfWeek.MONDAY and enum_value != DayOfWeek.FRIDAY
    return result
");

    var stopwatch = Stopwatch.StartNew();
    Assert.IsTrue(module.InvokeMethod("test").As<bool>());
    stopwatch.Stop();
    Console.WriteLine($"Total time: {stopwatch.Elapsed.TotalSeconds}s");
}

Master:

Total time: 18.6504161s
Total time: 19.0529056s
Total time: 19.0023384s
Total time: 18.5928232s
Total time: 18.7222117s

Avg: 18.8s

Branch:

Total time: 0.5745701s
Total time: 0.5748509s
Total time: 0.5982596s
Total time: 0.5831667s
Total time: 0.564322s

Avg: 0.58s

The test is ~32x faster.

@jhonabreul jhonabreul merged commit 1aa5b8b into QuantConnect:master Aug 14, 2025
0 of 21 checks passed
@jhonabreul jhonabreul deleted the refactor-enum-comparison-operators-performance branch August 14, 2025 15:29
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

Successfully merging this pull request may close these issues.

2 participants