Last active
December 26, 2015 05:39
-
-
Save mishok13/7102652 to your computer and use it in GitHub Desktop.
Line by line reading
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
user> (defn c [p] | |
(with-open [rdr (clojure.java.io/reader p)] | |
(reduce + (map count (line-seq rdr))))) | |
#'user/c | |
user> (bench/quick-bench | |
(c "/tmp/test")) | |
WARNING: Final GC required 356.7754050400232 % of runtime | |
Evaluation count : 6 in 6 samples of 1 calls. | |
Execution time mean : 525.040480 ms | |
Execution time std-deviation : 29.017225 ms | |
Execution time lower quantile : 491.257955 ms ( 2.5%) | |
Execution time upper quantile : 563.009360 ms (97.5%) | |
Overhead used : 2.812543 ns | |
nil |
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
In [1]: def c(p): | |
...: with open(p) as f: | |
...: return sum(len(line.strip()) for line in f) | |
...: | |
In [10]: %timeit -n100 c("/tmp/test") | |
100 loops, best of 3: 288 ms per loop |
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
user> (require '[clojure.core.reducers :as r]) | |
nil | |
user> (defn c3 [p] | |
(with-open [rdr (clojure.java.io/reader p)] | |
(r/reduce + 0 (r/map len (line-seq rdr))))) | |
#'user/c3 | |
user> (bench/quick-bench | |
(c3 "/tmp/test")) | |
WARNING: Final GC required 587.4416454410667 % of runtime | |
Evaluation count : 6 in 6 samples of 1 calls. | |
Execution time mean : 319.255797 ms | |
Execution time std-deviation : 74.168228 ms | |
Execution time lower quantile : 259.756586 ms ( 2.5%) | |
Execution time upper quantile : 436.680869 ms (97.5%) | |
Overhead used : 2.812543 ns | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment