Skip to content

Instantly share code, notes, and snippets.

@jwmerrill
Last active December 30, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwmerrill/7866141 to your computer and use it in GitHub Desktop.
Save jwmerrill/7866141 to your computer and use it in GitHub Desktop.
Benchmark of PowerSeries.jl
using PowerSeries
function series_loop()
accum = 0.0
for i = 1:10000
accum += sin(Series(1.0*i, 1.0)).ep
end
end
function dual_loop()
accum = 0.0
for i = 1:10000
accum += sin(Dual(1.0*i, 1.0)).ep
end
end
function bare_loop()
accum = 0.0
for i = 1:10000
accum += cos(1.0*i)
end
end
# Warm up JIT
@assert series_loop() == bare_loop()
@assert dual_loop() == bare_loop()
tseries = @elapsed series_loop()
tdual = @elapsed dual_loop()
tbare = @elapsed bare_loop()
println("Series time")
println("Series", ", ", "Bare", ", ", "Ratio")
println(tseries, ", ", tbare, ", ", tseries/tbare)
println("\n")
println("Dual time")
println("Dual", ", ", "Bare", ", ", "Ratio")
println(tdual, ", ", tbare, ", ", tdual/tbare)
println("\n")
println("Series code")
code_native(series_loop, ())
println("\n")
println("Dual code")
code_native(dual_loop, ())
println("\n")
println("Bare code")
code_native(bare_loop, ())
Series time
Series, Bare, Ratio
0.007756515, 0.000455254, 17.037774517082774
Dual time
Dual, Bare, Ratio
0.000912513, 0.000455254, 2.00440413483462
Series code
.section __TEXT,__text,regular,pure_instructions
Filename: /Users/jm843/.julia/PowerSeries/test/benchmark.jl
Source line: 4
push RBP
mov RBP, RSP
push R15
push R14
push R13
push R12
push RBX
sub RSP, 40
mov QWORD PTR [RBP - 80], 6
Source line: 4
movabs RAX, 4514005616
mov RCX, QWORD PTR [RAX]
mov QWORD PTR [RBP - 72], RCX
lea RCX, QWORD PTR [RBP - 80]
mov QWORD PTR [RAX], RCX
mov QWORD PTR [RBP - 56], 0
mov QWORD PTR [RBP - 48], 0
movabs RAX, 140405771348064
Source line: 4
mov QWORD PTR [RBP - 64], RAX
mov EBX, 1
movabs R13, 140405773393920
movabs R14, 140405771348176
Source line: 6
movabs R15, 4529856016
movabs R12, 4501855296
mov QWORD PTR [RBP - 56], RAX
mov EDI, 24
movabs RAX, 4502150720
call RAX
mov QWORD PTR [RAX], R13
cvtsi2sd XMM0, RBX
movsd QWORD PTR [RAX + 8], XMM0
mov QWORD PTR [RAX + 16], R14
mov QWORD PTR [RBP - 48], RAX
movabs RDI, 140405773111648
lea RSI, QWORD PTR [RBP - 48]
mov EDX, 1
call R15
mov RAX, QWORD PTR [RAX + 16]
test RAX, RAX
je 78
mov QWORD PTR [RBP - 48], RAX
movabs RDI, 140405766580864
lea RSI, QWORD PTR [RBP - 56]
mov EDX, 2
call R12
mov QWORD PTR [RBP - 64], RAX
inc RBX
cmp RBX, 10001
jl -123
mov RAX, QWORD PTR [RBP - 72]
movabs RCX, 4514005616
mov QWORD PTR [RCX], RAX
add RSP, 40
pop RBX
pop R12
pop R13
pop R14
pop R15
pop RBP
ret
movabs RAX, 4514005152
mov RDI, QWORD PTR [RAX]
movabs RAX, 4502100144
mov ESI, 6
call RAX
Dual code
.section __TEXT,__text,regular,pure_instructions
Filename: /Users/jm843/.julia/PowerSeries/test/benchmark.jl
Source line: 13
push RBP
mov RBP, RSP
push R15
push R14
push RBX
push RAX
mov EBX, 1
Source line: 13
movabs R14, 4608432224
movabs R15, 4608414480
xorps XMM0, XMM0
cvtsi2sd XMM0, RBX
movsd QWORD PTR [RBP - 32], XMM0
call R14
ucomisd XMM0, XMM0
jp 39
movsd XMM0, QWORD PTR [RBP - 32]
call R15
ucomisd XMM0, XMM0
jp 41
inc RBX
cmp RBX, 10000
jg 70
jmpq -65
movsd XMM0, QWORD PTR [RBP - 32]
ucomisd XMM0, XMM0
jnp 20
jmpq -59
movsd XMM0, QWORD PTR [RBP - 32]
ucomisd XMM0, XMM0
jp -56
movabs RAX, 4514005128
mov RDI, QWORD PTR [RAX]
movabs RAX, 4502100144
mov ESI, 13
call RAX
add RSP, 8
pop RBX
pop R14
pop R15
pop RBP
ret
Bare code
.section __TEXT,__text,regular,pure_instructions
Filename: /Users/jm843/.julia/PowerSeries/test/benchmark.jl
Source line: 20
push RBP
mov RBP, RSP
push R14
push RBX
sub RSP, 16
mov EBX, 1
Source line: 20
movabs R14, 4608414480
xorps XMM0, XMM0
cvtsi2sd XMM0, RBX
movsd QWORD PTR [RBP - 24], XMM0
call R14
ucomisd XMM0, XMM0
jp 21
inc RBX
cmp RBX, 10000
jg 50
jmpq -47
movsd XMM0, QWORD PTR [RBP - 24]
ucomisd XMM0, XMM0
jp -36
movabs RAX, 4514005128
mov RDI, QWORD PTR [RAX]
movabs RAX, 4502100144
mov ESI, 20
call RAX
add RSP, 16
pop RBX
pop R14
pop RBP
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment