Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up compare functions #1249

Merged
merged 1 commit into from Aug 12, 2023
Merged

Speed up compare functions #1249

merged 1 commit into from Aug 12, 2023

Conversation

primo-ppcg
Copy link
Contributor

@primo-ppcg primo-ppcg commented Aug 11, 2023

  • Makes compare-reduce a macro so that the comparators, which are known at compile time, compile to vm ops rather than function calls.
  • Inlines the call to compare in the compare-reduce macro.

The result is approximately 75% faster for abstract types, and 130% as faster for numbers per invocation.

(use spork/test)

(def a (range 10))

(timeit-loop [:repeat 1_000_000] "control " (< ;a))
(timeit-loop [:repeat 1_000_000] "splice  " (compare< ;a))
(timeit-loop [:repeat 1_000_000] "number  " (compare< 0 1))
(timeit-loop [:repeat 1_000_000] "s64 arg0" (compare< (int/s64 0) 1))
(timeit-loop [:repeat 1_000_000] "s64 arg1" (compare< 0 (int/s64 1)))

master:

control  0.213s, 0.2134µs/body
splice   1.792s, 1.792µs/body
number   0.296s, 0.2964µs/body
s64 arg0 0.397s, 0.3967µs/body
s64 arg1 0.402s, 0.4023µs/body

branch:

control  0.214s, 0.2142µs/body
splice   0.408s, 0.4084µs/body
number   0.128s, 0.1281µs/body
s64 arg0 0.222s, 0.2224µs/body
s64 arg1 0.234s, 0.2338µs/body

@bakpakin bakpakin merged commit 7475362 into janet-lang:master Aug 12, 2023
8 checks passed
@primo-ppcg primo-ppcg deleted the compare branch August 12, 2023 01:25
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.

None yet

2 participants