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