Skip to content

Commit 174c1fa

Browse files
authored
More robustly prevent compiler from eliminating code to be benchmarked
1 parent eae2705 commit 174c1fa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/LinuxPerf.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,12 @@ macro pstats(args...)
11401140
try
11411141
enable_all!()
11421142
val = $(esc(expr))
1143+
@static if isdefined(Base, :donotdelete)
1144+
Base.donotdelete(val)
1145+
end
11431146
disable_all!()
11441147
# trick the compiler not to eliminate the code
1145-
stats = rand() < 0 ? val : Stats(bench)
1148+
stats = @noinline rand() < 0 ? val : Stats(bench)
11461149
return stats::Stats
11471150
catch
11481151
rethrow()

0 commit comments

Comments
 (0)