Skip to content

Commit 4f78589

Browse files
ericphansonMilesCranmer
authored andcommitted
timing + benchmark
1 parent fcc687a commit 4f78589

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

gcbench.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using PythonCall, Test
2+
3+
# https://github.com/JuliaCI/GCBenchmarks/blob/fc288c696381ebfdef8f002168addd0ec1b08e34/benches/serial/append/append.jl
4+
macro gctime(ex)
5+
quote
6+
local prior = PythonCall.GC.SECONDS_SPENT_IN_GC[]
7+
local ret = @timed $(esc(ex))
8+
Base.time_print(stdout, ret.time * 1e9, ret.gcstats.allocd, ret.gcstats.total_time, Base.gc_alloc_count(ret.gcstats); msg="Runtime")
9+
local after = PythonCall.GC.SECONDS_SPENT_IN_GC[]
10+
println(stdout)
11+
Base.time_print(stdout, (after - prior) * 1e9; msg="Python GC time")
12+
println(stdout)
13+
ret.value
14+
end
15+
end
16+
17+
function append_lots(iters=100 * 1024, size=1596)
18+
v = pylist()
19+
for i = 1:iters
20+
v.append(pylist(rand(size)))
21+
end
22+
return v
23+
end
24+
25+
@time "Total" begin
26+
@gctime append_lots()
27+
@time "Next full GC" begin
28+
GC.gc(true)
29+
end
30+
end

0 commit comments

Comments
 (0)