Last active
September 28, 2016 14:50
-
-
Save vvvvalvalval/0b6be04c0191cce6fa09bba8f821b967 to your computer and use it in GitHub Desktop.
Benchmark data for StackOverflow question: http://stackoverflow.com/questions/39654782/how-do-i-check-whether-a-string-is-uppercase-or-not-in-clojure/39656499#39656499
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(set! *warn-on-reflection* true) | |
;; 3 competing implementations which test if a string is uppercase (note that the StringUtils one has some caveats regarding its semantics) | |
(defn p1 [^String s] | |
(= s (str/upper-case s))) | |
(defn p2 [^String s] | |
(every? (fn [^Character c] (Character/isUpperCase c)) s)) | |
(import org.apache.commons.lang3.StringUtils) | |
(defn p3 [^String s] | |
(StringUtils/isAllUpperCase s)) | |
(require '[criterium.core :as bench]) | |
(bench/bench | |
(let [p p1] | |
(p "coucou") | |
(p "Coucou") | |
(p "") | |
(p "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA") | |
(p " AAAAA a") | |
(p "FA3AEAAAAAAAAA4AAAAAAABAAAAAAb") | |
)) | |
;Evaluation count : 74244840 in 60 samples of 1237414 calls. | |
; Execution time mean : 782.701501 ns | |
; Execution time std-deviation : 97.513671 ns | |
; Execution time lower quantile : 606.340774 ns ( 2.5%) | |
; Execution time upper quantile : 959.838592 ns (97.5%) | |
; Overhead used : 2.280109 ns | |
(bench/bench | |
(let [p p2] | |
(p "coucou") | |
(p "Coucou") | |
(p "") | |
(p "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA") | |
(p " AAAAA a") | |
(p "FA3AEAAAAAAAAA4AAAAAAABAAAAAAb") | |
)) | |
;Evaluation count : 30735540 in 60 samples of 512259 calls. | |
; Execution time mean : 2.149382 µs | |
; Execution time std-deviation : 244.568748 ns | |
; Execution time lower quantile : 1.654448 µs ( 2.5%) | |
; Execution time upper quantile : 2.591681 µs (97.5%) | |
; Overhead used : 2.280109 ns | |
; | |
;Found 1 outliers in 60 samples (1.6667 %) | |
; low-severe 1 (1.6667 %) | |
; Variance from outliers : 75.4844 % Variance is severely inflated by outliers | |
(bench/bench | |
(let [p p3] | |
(p "coucou") | |
(p "Coucou") | |
(p "") | |
(p "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA") | |
(p " AAAAA a") | |
(p "FA3AEAAAAAAAAA4AAAAAAABAAAAAAb") | |
)) | |
;Evaluation count : 1324237920 in 60 samples of 22070632 calls. | |
; Execution time mean : 51.473188 ns | |
; Execution time std-deviation : 5.440066 ns | |
; Execution time lower quantile : 42.837131 ns ( 2.5%) | |
; Execution time upper quantile : 61.430209 ns (97.5%) | |
; Overhead used : 2.280109 ns | |
; | |
;Found 1 outliers in 60 samples (1.6667 %) | |
; low-severe 1 (1.6667 %) | |
; Variance from outliers : 72.0795 % Variance is severely inflated by outliers | |
;; Context: | |
;Hardware Overview: | |
; Model Name: MacBook Air | |
; Model Identifier: MacBookAir7,1 | |
; Processor Name: Intel Core i7 | |
; Processor Speed: 2,2 GHz | |
; Number of Processors: 1 | |
; Total Number of Cores: 2 | |
; L2 Cache (per Core): 256 KB | |
; L3 Cache: 4 MB | |
; Memory: 8 GB | |
;System Software Overview: | |
; System Version: OS X 10.10.5 (14F27) | |
; Kernel Version: Darwin 14.5.0 | |
; Boot Volume: Macintosh HD | |
; Boot Mode: Normal | |
; Secure Virtual Memory: Enabled | |
; Time since boot: 35 minutes | |
; Java version | |
;java version "1.8.0_05" | |
;Java(TM) SE Runtime Environment (build 1.8.0_05-b13) | |
;Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) | |
;Clojure 1.8.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment