@@ -699,6 +699,36 @@ See http://www.ellipticgroup.com/misc/article_supplement.pdf, p17."
699
699
(outlier-count 0 0 0 0 )
700
700
data))
701
701
702
+ ; ;; overhead estimation
703
+ (declare benchmark* )
704
+
705
+ (defn estimate-overhead
706
+ " Calculate a conservative estimate of the timing loop overhead."
707
+ []
708
+ (-> (benchmark*
709
+ (fn [] 0 )
710
+ {:warmup-jit-period (* 10 s-to-ns)
711
+ :samples 10
712
+ :target-execution-time (* 0.5 s-to-ns)
713
+ :overhead 0
714
+ :supress-jvm-option-warnings true })
715
+ :lower-q
716
+ first))
717
+
718
+ (def estimatated-overhead-cache nil )
719
+
720
+ (defn estimatated-overhead!
721
+ " Sets the estimated overhead."
722
+ []
723
+ (progress " Estimating sampling overhead" )
724
+ (alter-var-root
725
+ #'estimatated-overhead-cache (constantly (estimate-overhead ))))
726
+
727
+ (defn estimatated-overhead
728
+ []
729
+ (or estimatated-overhead-cache
730
+ (estimatated-overhead! )))
731
+
702
732
; ;; options
703
733
(defn extract-report-options
704
734
" Extract reporting options from the given options vector. Returns a two
@@ -779,7 +809,6 @@ See http://www.ellipticgroup.com/misc/article_supplement.pdf, p17."
779
809
" and may lead to unexpected results as JIT C2 compiler may not be active."
780
810
" See http://www.slideshare.net/CharlesNutter/javaone-2012-jvm-jit-for-dummies." ))))
781
811
782
-
783
812
(defn benchmark*
784
813
" Benchmark a function. This tries its best to eliminate sources of error.
785
814
This also means that it runs for a while. It will typically take 70s for a
@@ -791,7 +820,9 @@ See http://www.ellipticgroup.com/misc/article_supplement.pdf, p17."
791
820
(warn-on-suspicious-jvm-options ))
792
821
(let [{:keys [samples warmup-jit-period target-execution-time
793
822
gc-before-sample overhead] :as opts}
794
- (merge *default-benchmark-opts* options)
823
+ (merge *default-benchmark-opts*
824
+ {:overhead (or overhead (estimatated-overhead ))}
825
+ options)
795
826
times (run-benchmark
796
827
samples warmup-jit-period target-execution-time f opts overhead)]
797
828
(benchmark-stats times opts)))
@@ -954,30 +985,6 @@ See http://www.ellipticgroup.com/misc/article_supplement.pdf, p17."
954
985
(report-point-estimate " Overhead used" [overhead])))
955
986
(report-outliers results)))
956
987
957
- (defn estimate-overhead
958
- " Calculate a conservative estimate of the timing loop overhead."
959
- []
960
- (-> (benchmark 0 {:warmup-jit-period (* 10 s-to-ns)
961
- :samples 10
962
- :target-execution-time (* 0.5 s-to-ns)
963
- :overhead 0 })
964
- :lower-q
965
- first))
966
-
967
- (def estimatated-overhead-cache nil )
968
-
969
- (defn estimatated-overhead!
970
- " Sets the estimated overhead."
971
- []
972
- (progress " Estimating sampling overhead" )
973
- (alter-var-root
974
- #'estimatated-overhead-cache (constantly (estimate-overhead ))))
975
-
976
- (defn estimatated-overhead
977
- []
978
- (or estimatated-overhead-cache
979
- (estimatated-overhead! )))
980
-
981
988
(defmacro bench
982
989
" Convenience macro for benchmarking an expression, expr. Results are reported
983
990
to *out* in human readable format. Options for report format are: :os,
@@ -987,8 +994,7 @@ See http://www.ellipticgroup.com/misc/article_supplement.pdf, p17."
987
994
`(report-result
988
995
(benchmark
989
996
~expr
990
- (merge {:overhead (estimatated-overhead )}
991
- ~(when (seq options) (apply hash-map options))))
997
+ ~(when (seq options) (apply hash-map options)))
992
998
~@report-options)))
993
999
994
1000
(defmacro quick-bench
@@ -1000,6 +1006,5 @@ to *out* in human readable format. Options for report format are: :os,
1000
1006
`(report-result
1001
1007
(quick-benchmark
1002
1008
~expr
1003
- (merge {:overhead (estimatated-overhead )}
1004
- ~(when (seq options) (apply hash-map options))))
1009
+ ~(when (seq options) (apply hash-map options)))
1005
1010
~@report-options)))
0 commit comments