Created
December 31, 2015 23:42
-
-
Save noisesmith/b3ea6e44615613a0d458 to your computer and use it in GitHub Desktop.
various ways to convert 1/0 into true/false
This file contains 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
;; tl;dr - fastest is if, then complement, then map literal, then lambda using get | |
user=> (def input [0 1 0 0 0 1 1 1 0 1 0 1]) | |
#'user/input | |
user=> (crit/bench (doseq [i input] ({0 false 1 true} i))) | |
Evaluation count : 167321340 in 60 samples of 2788689 calls. | |
Execution time mean : 355.195418 ns | |
Execution time std-deviation : 4.916042 ns | |
Execution time lower quantile : 349.279345 ns ( 2.5%) | |
Execution time upper quantile : 365.384165 ns (97.5%) | |
Overhead used : 1.858366 ns | |
Found 1 outliers in 60 samples (1.6667 %) | |
low-severe 1 (1.6667 %) | |
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers | |
nil | |
user=> (crit/bench (doseq [i input] ((complement zero?) i))) | |
Evaluation count : 464564640 in 60 samples of 7742744 calls. | |
Execution time mean : 128.041507 ns | |
Execution time std-deviation : 1.119082 ns | |
Execution time lower quantile : 126.723904 ns ( 2.5%) | |
Execution time upper quantile : 130.748764 ns (97.5%) | |
Overhead used : 1.858366 ns | |
Found 7 outliers in 60 samples (11.6667 %) | |
low-severe 5 (8.3333 %) | |
low-mild 2 (3.3333 %) | |
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers | |
nil | |
user=> (crit/bench (doseq [i input] (#(if (zero? %) false true) i))) | |
Evaluation count : 616573380 in 60 samples of 10276223 calls. | |
Execution time mean : 96.695141 ns | |
Execution time std-deviation : 1.318004 ns | |
Execution time lower quantile : 94.558605 ns ( 2.5%) | |
Execution time upper quantile : 99.270862 ns (97.5%) | |
Overhead used : 1.858366 ns | |
nil | |
user=> (crit/bench (doseq [i input] (#(get {0 false 1 true} %) i))) | |
Evaluation count : 146799120 in 60 samples of 2446652 calls. | |
Execution time mean : 420.625272 ns | |
Execution time std-deviation : 7.550235 ns | |
Execution time lower quantile : 408.822148 ns ( 2.5%) | |
Execution time upper quantile : 436.475298 ns (97.5%) | |
Overhead used : 1.858366 ns | |
nil | |
user=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment