oscbyspro / AwesomeNumbersKit

Large number arithmetic in Swift
Apache License 2.0
7 stars 1 forks source link

Improved `Int` strides #151

Closed oscbyspro closed 1 year ago

oscbyspro commented 1 year ago

From https://github.com/oscbyspro/Numberick/issues/36

I saw that signed distance(to:) and advanced(by:) were slow, so I'll add my own implementation:

// current

Test Case '-[NBKDoubleWidthKitBenchmarks. Int256BenchmarksOnStrides testAdvancedBy]' passed (0.018 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks. Int256BenchmarksOnStrides testDistanceTo]' passed (0.014 seconds).

Test Case '-[NBKDoubleWidthKitBenchmarks.UInt256BenchmarksOnStrides testAdvancedBy]' passed (0.003 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks.UInt256BenchmarksOnStrides testDistanceTo]' passed (0.004 seconds).

// with custom implementation

Test Case '-[NBKDoubleWidthKitBenchmarks. Int256BenchmarksOnStrides testAdvancedBy]' passed (0.004 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks. Int256BenchmarksOnStrides testDistanceTo]' passed (0.004 seconds).

Test Case '-[NBKDoubleWidthKitBenchmarks.UInt256BenchmarksOnStrides testAdvancedBy]' passed (0.003 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks.UInt256BenchmarksOnStrides testDistanceTo]' passed (0.004 seconds).