Skip to content

Instantly share code, notes, and snippets.

@qerub
Last active December 31, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qerub/8031665 to your computer and use it in GitHub Desktop.
Save qerub/8031665 to your computer and use it in GitHub Desktop.
[Clojure/Java] Benchmarks of different ways of splitting a string by a char
# Benchmarking (.split test-input "\\.")
Evaluation count : 72101040 in 60 samples of 1201684 calls.
Execution time mean : 828.458928 ns
Execution time std-deviation : 29.055494 ns
Execution time lower quantile : 800.771006 ns ( 2.5%)
Execution time upper quantile : 895.752028 ns (97.5%)
Overhead used : 2.778847 ns
Found 5 outliers in 60 samples (8.3333 %)
low-severe 2 (3.3333 %)
low-mild 3 (5.0000 %)
Variance from outliers : 22.1807 % Variance is moderately inflated by outliers
# Benchmarking (.split #"\." test-input)
Evaluation count : 96236220 in 60 samples of 1603937 calls.
Execution time mean : 629.194967 ns
Execution time std-deviation : 17.581353 ns
Execution time lower quantile : 611.170657 ns ( 2.5%)
Execution time upper quantile : 685.200170 ns (97.5%)
Overhead used : 2.778847 ns
Found 5 outliers in 60 samples (8.3333 %)
low-severe 2 (3.3333 %)
low-mild 3 (5.0000 %)
Variance from outliers : 15.7402 % Variance is moderately inflated by outliers
# Benchmarking (org.apache.commons.lang3.StringUtils/split test-input \.)
Evaluation count : 335815860 in 60 samples of 5596931 calls.
Execution time mean : 177.416984 ns
Execution time std-deviation : 5.619332 ns
Execution time lower quantile : 171.281009 ns ( 2.5%)
Execution time upper quantile : 191.734901 ns (97.5%)
Overhead used : 2.778847 ns
Found 7 outliers in 60 samples (11.6667 %)
low-severe 2 (3.3333 %)
low-mild 5 (8.3333 %)
Variance from outliers : 18.9616 % Variance is moderately inflated by outliers
;; lein try criterium org.apache.commons/commons-lang3
(use 'criterium.core)
(defmacro multibench [& exprs]
`(do ~@(for [expr# exprs]
`(do (println "#" "Benchmarking" (pr-str '~expr#))
(println)
(bench ~expr#)
(println)))))
(def ^String test-input "foo.bar.baz.foo.bar.baz")
(multibench (.split test-input "\\.")
(.split #"\." test-input)
(org.apache.commons.lang3.StringUtils/split test-input \.))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment