Skip to content

Commit

Permalink
Test performance of "iteration" over numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed May 31, 2016
1 parent f29b74e commit b643998
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/scalar/ScalarBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,35 @@ for X in NUMS
end
end

#############
# iteration #
#############

function perf_iterate_indexed(n, v)
s = 0
for i = 1:n
for j = 1:1
@inbounds k = v[j]
s += k
end
end
s
end

function perf_iterate_in(n, v)
s = 0
for i = 1:n
for k in v
s += k
end
end
s
end

g = addgroup!(SUITE, "iteration", ["indexed", "in"])

g["indexed"] = @benchmarkable perf_iterate_indexed(10^5, 3)
g["in"] = @benchmarkable perf_iterate_in(10^5, 3)


end # module

3 comments on commit b643998

@pabloferz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timholy I have a question regarding these. Did you wrote them like this mainly to make sure that no regressions occur in the future (not getting optimized away)?

Cause @code_native gives

.text
Filename: REPL[2]
    pushq   %rbp
    movq    %rsp, %rbp
    xorl    %eax, %eax
Source line: 3
    testq   %rdi, %rdi
    jle L18
    imulq   %rdi, %rsi
    movq    %rsi, %rax
Source line: 8
L18:
    popq    %rbp
    retq
    nopw    %cs:(%rax,%rax)

for both of them.

@timholy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you wrote them like this mainly to make sure that no regressions occur in the future (not getting optimized away)?

Correct. See JuliaLang/julia#17230 and the links therein for the full history.

@pabloferz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you for the pointers and sorry for the noise.

Please sign in to comment.