Skip to content

Commit 70e9934

Browse files
authored
Merge pull request #48 from JuliaPerf/Zentrik/robust-donotdelete
More robustly prevent compiler from eliminating code to be benchmarked
2 parents eae2705 + 7c8e4d7 commit 70e9934

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/LinuxPerf.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,12 @@ macro pstats(args...)
11421142
val = $(esc(expr))
11431143
disable_all!()
11441144
# trick the compiler not to eliminate the code
1145-
stats = rand() < 0 ? val : Stats(bench)
1145+
@static if isdefined(Base, :donotdelete)
1146+
Base.donotdelete(val)
1147+
stats = Stats(bench)
1148+
else
1149+
stats = (@noinline rand()) < 0 ? val : Stats(bench)
1150+
end
11461151
return stats::Stats
11471152
catch
11481153
rethrow()

0 commit comments

Comments
 (0)