@@ -121,9 +121,9 @@ function _run(b::Benchmark, p::Parameters; verbose=false, pad="", warmup=true, k
121
121
return_val = trial_contents. __return_val
122
122
iters = 2
123
123
while (Base. time () - start_time) < params. seconds && iters ≤ params. samples
124
- params. gcsample && gcscrub ()
125
- push! (trial, b. samplefunc (b. quote_vals, params))
126
- iters += 1
124
+ params. gcsample && gcscrub ()
125
+ push! (trial, b. samplefunc (b. quote_vals, params))
126
+ iters += 1
127
127
end
128
128
return trial, return_val
129
129
end
@@ -547,67 +547,82 @@ function generate_benchmark_definition(
547
547
core_body = :($ (core); $ (returns))
548
548
end
549
549
@static if isdefined (Base, :donotdelete )
550
- invocation = :(let x = $ invocation
551
- Base. donotdelete (x)
552
- x
553
- end )
550
+ invocation = :(
551
+ let x = $ invocation
552
+ Base. donotdelete (x)
553
+ x
554
+ end
555
+ )
554
556
end
555
557
experimental_enable_linux_perf = true # TODO : take this as input from the user
556
558
# TODO : let the user actually provide these options.
557
559
linux_perf_opts = LinuxPerf. parse_pstats_options ([])
558
- return Core. eval (eval_module, quote
559
- @noinline $ (signature_def) = begin $ (core_body) end
560
- @noinline function $ (samplefunc)($ (Expr (:tuple , quote_vars... )), __params:: $BenchmarkTools.Parameters )
561
- $ (setup)
562
- __evals = __params. evals
563
- __gc_start = Base. gc_num ()
564
- __start_time = time_ns ()
565
- __return_val = $ (invocation)
566
- for __iter in 2 : __evals
567
- $ (invocation)
560
+ return Core. eval (
561
+ eval_module,
562
+ quote
563
+ @noinline $ (signature_def) = begin
564
+ $ (core_body)
568
565
end
569
- __sample_time = time_ns () - __start_time
570
- __gcdiff = Base. GC_Diff (Base. gc_num (), __gc_start)
571
- $ (teardown)
572
- __time = max ((__sample_time / __evals) - __params. overhead, 0.001 )
573
- __gctime = max ((__gcdiff. total_time / __evals) - __params. overhead, 0.0 )
574
- __memory = Int (Base. fld (__gcdiff. allocd, __evals))
575
- __allocs = Int (Base. fld (__gcdiff. malloc + __gcdiff. realloc +
576
- __gcdiff. poolalloc + __gcdiff. bigalloc,
577
- __evals))
578
- if $ (experimental_enable_linux_perf)
579
- # Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
580
- __linux_perf_groups = BenchmarkTools. LinuxPerf. set_default_spaces (
581
- $ (linux_perf_opts. events),
582
- $ (linux_perf_opts. spaces),
583
- )
584
- __linux_perf_bench = BenchmarkTools. LinuxPerf. make_bench_threaded (
585
- __linux_perf_groups;
586
- threads = $ (linux_perf_opts. threads),
566
+ @noinline function $ (samplefunc)(
567
+ $ (Expr (:tuple , quote_vars... )), __params:: $BenchmarkTools.Parameters
568
+ )
569
+ $ (setup)
570
+ __evals = __params. evals
571
+ __gc_start = Base. gc_num ()
572
+ __start_time = time_ns ()
573
+ __return_val = $ (invocation)
574
+ for __iter in 2 : __evals
575
+ $ (invocation)
576
+ end
577
+ __sample_time = time_ns () - __start_time
578
+ __gcdiff = Base. GC_Diff (Base. gc_num (), __gc_start)
579
+ $ (teardown)
580
+ __time = max ((__sample_time / __evals) - __params. overhead, 0.001 )
581
+ __gctime = max ((__gcdiff. total_time / __evals) - __params. overhead, 0.0 )
582
+ __memory = Int (Base. fld (__gcdiff. allocd, __evals))
583
+ __allocs = Int (
584
+ Base. fld (
585
+ __gcdiff. malloc +
586
+ __gcdiff. realloc +
587
+ __gcdiff. poolalloc +
588
+ __gcdiff. bigalloc,
589
+ __evals,
590
+ ),
587
591
)
588
- BenchmarkTools. LinuxPerf. enable! (__linux_perf_bench)
589
- # We'll just run it one time.
590
- __return_val_2 = $ (invocation)
591
- BenchmarkTools. LinuxPerf. disable! (__linux_perf_bench)
592
- # trick the compiler not to eliminate the code
593
- if rand () < 0
594
- __linux_perf_stats = __return_val_2
595
- else
596
- __linux_perf_stats = BenchmarkTools. LinuxPerf. Stats (__linux_perf_bench)
592
+ if $ (experimental_enable_linux_perf)
593
+ # Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
594
+ __linux_perf_groups = BenchmarkTools. LinuxPerf. set_default_spaces (
595
+ $ (linux_perf_opts. events), $ (linux_perf_opts. spaces)
596
+ )
597
+ __linux_perf_bench = BenchmarkTools. LinuxPerf. make_bench_threaded (
598
+ __linux_perf_groups; threads= $ (linux_perf_opts. threads)
599
+ )
600
+ BenchmarkTools. LinuxPerf. enable! (__linux_perf_bench)
601
+ # We'll just run it one time.
602
+ __return_val_2 = $ (invocation)
603
+ BenchmarkTools. LinuxPerf. disable! (__linux_perf_bench)
604
+ # trick the compiler not to eliminate the code
605
+ if rand () < 0
606
+ __linux_perf_stats = __return_val_2
607
+ else
608
+ __linux_perf_stats = BenchmarkTools. LinuxPerf. Stats (
609
+ __linux_perf_bench
610
+ )
611
+ end
597
612
end
613
+ return (;
614
+ __time,
615
+ __gctime,
616
+ __memory,
617
+ __allocs,
618
+ __return_val,
619
+ __return_val_2,
620
+ __linux_perf_stats,
621
+ )
598
622
end
599
- return (;
600
- __time,
601
- __gctime,
602
- __memory,
603
- __allocs,
604
- __return_val,
605
- __return_val_2,
606
- __linux_perf_stats,
607
- )
608
- end
609
- $ BenchmarkTools. Benchmark ($ (samplefunc), $ (quote_vals), $ (params))
610
- end )
623
+ $ BenchmarkTools. Benchmark ($ (samplefunc), $ (quote_vals), $ (params))
624
+ end ,
625
+ )
611
626
end
612
627
613
628
# #####################
0 commit comments