SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
120 stars 15 forks source link

Performance improvements for Unitful conversion #141

Closed Deduction42 closed 1 month ago

Deduction42 commented 1 month ago

Fix for issue #139, major (~500x) performance improvements when converting from Unitful to DynamicUnits, minor improvements to reverse case.

github-actions[bot] commented 1 month ago

Benchmark Results

main 2601bdd79af521... main/2601bdd79af521...
Quantity/creation/Quantity(x) 2.79 ± 0 ns 3.11 ± 0.01 ns 0.9
Quantity/creation/Quantity(x, length=y) 3.42 ± 0.01 ns 3.11 ± 0.001 ns 1.1
Quantity/with_numbers/*real 3.11 ± 0.01 ns 3.11 ± 0.001 ns 1
Quantity/with_numbers/^int 8.37 ± 2.5 ns 8.68 ± 2.5 ns 0.964
Quantity/with_numbers/^int * real 8.05 ± 2.2 ns 8.37 ± 2.2 ns 0.963
Quantity/with_quantity/+y 4.04 ± 0.01 ns 4.04 ± 0.01 ns 1
Quantity/with_quantity//y 3.11 ± 0.001 ns 3.42 ± 0.01 ns 0.909
Quantity/with_self/dimension 2.79 ± 0 ns 3.1 ± 0.01 ns 0.9
Quantity/with_self/inv 3.11 ± 0.001 ns 3.41 ± 0.01 ns 0.912
Quantity/with_self/ustrip 2.79 ± 0.01 ns 3.1 ± 0.01 ns 0.903
QuantityArray/broadcasting/multi_array_of_quantities 0.146 ± 0.0017 ms 0.143 ± 0.0012 ms 1.02
QuantityArray/broadcasting/multi_normal_array 0.0528 ± 0.0029 ms 0.0528 ± 0.0017 ms 0.999
QuantityArray/broadcasting/multi_quantity_array 0.157 ± 0.00077 ms 0.157 ± 0.00075 ms 0.999
QuantityArray/broadcasting/x^2_array_of_quantities 24 ± 2 μs 23.8 ± 1.6 μs 1.01
QuantityArray/broadcasting/x^2_normal_array 4.14 ± 1.5 μs 4.26 ± 1 μs 0.972
QuantityArray/broadcasting/x^2_quantity_array 7.13 ± 27 μs 7.11 ± 28 μs 1
QuantityArray/broadcasting/x^4_array_of_quantities 0.0844 ± 0.00056 ms 0.0814 ± 0.00075 ms 1.04
QuantityArray/broadcasting/x^4_normal_array 0.0498 ± 0.00018 ms 0.0498 ± 0.00019 ms 1
QuantityArray/broadcasting/x^4_quantity_array 0.0499 ± 0.0002 ms 0.0499 ± 0.00022 ms 1
time_to_load 0.143 ± 0.0012 s 0.144 ± 0.0019 s 0.992

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

MilesCranmer commented 1 month ago

Seems to be failing the tests?

Deduction42 commented 1 month ago

Is it passing the tests now? I see a green checkmark on "Benchmark a pull request" workflow. I has one workflow awaiting approval. Is there something else I need to look at for the tests?

Deduction42 commented 1 month ago

Okay, I think I know what happened. I made some changes to Main on my side and I didn't know that the pull request tracked the current version of my repo. I revered those changes so that only the changes we discussed were made. Sorry about that.

Deduction42 commented 1 month ago

I ran the tests locally and they passed. Hopefully it will work now on your end.

MilesCranmer commented 1 month ago

Thanks for the PR!

Deduction42 commented 4 weeks ago

No problem!