Last active
November 18, 2023 22:26
-
-
Save Seelengrab/ba9dea884764804e8f60db97aaacde85 to your computer and use it in GitHub Desktop.
gotta load fast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools | |
using StarWarsArrays | |
only_bench(x) = only(x) | |
one_idx_bench(x) = x[1] | |
deref_bench(x) = x[] | |
first_bench(x) = first(x) | |
twod_one_idx_bench(x) = x[1,1] | |
splat_bench(x) = x[ones(Int, 100)...] | |
end_bench(x) = x[end] | |
begin_end_bench(x) = x[begin, end] | |
reduce_sum_bench(x) = reduce(sum, x) | |
floor_bench(x) = x[floor(Int, -real(exp(π * im)))] | |
cispi_bench(x) = x[floor(Int, -real(cispi(1)))] | |
unsafe_bench(x) = unsafe_load(pointer(x, 1)) | |
starwars_bench(x) = StarWarsArray(x)[4] # ಠ_ಠ | |
rand_bench(x) = rand(x) | |
function bench() | |
grp = BenchmarkGroup() | |
for f in [ | |
only_bench, | |
one_idx_bench, | |
deref_bench, | |
first_bench, | |
twod_one_idx_bench, | |
splat_bench, | |
end_bench, | |
begin_end_bench, | |
reduce_sum_bench, | |
floor_bench, | |
cispi_bench, | |
unsafe_bench, | |
starwars_bench, | |
rand_bench | |
] | |
println('\n', f, ':') | |
display(@benchmark $f(Ref(x)[]) setup=(x=rand(1,1))) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment