Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created November 15, 2013 04:58
Show Gist options
  • Save ryanlecompte/7479343 to your computer and use it in GitHub Desktop.
Save ryanlecompte/7479343 to your computer and use it in GitHub Desktop.
thyme comparisons
scala> val th = new ichi.bench.Thyme
th: ichi.bench.Thyme = ichi.bench.Thyme@105e4712
scala> val upperRx = "[A-Z]".r
upperRx: scala.util.matching.Regex = [A-Z]
scala> val lc = "alllowercase"
lc: String = alllowercase
scala> val uc1 = "Ryanlecompte"
uc1: String = Ryanlecompte
scala> val uc2 = "ryanleCompte"
uc2: String = ryanleCompte
scala> def meth1(s: String): Boolean = upperRx.findFirstIn(s).isEmpty
meth1: (s: String)Boolean
scala> def meth2(s: String): Boolean = s.forall { Character.isLowerCase(_) }
meth2: (s: String)Boolean
scala> th.pbench { meth1(lc) }
Benchmark (10485740 calls in 2.253 s)
Time: 198.0 ns 95% CI 189.1 ns - 206.8 ns (n=20)
Garbage: 2.861 ns (n=13 sweeps measured)
res0: Boolean = true
scala> th.pbench { meth2(lc) }
Benchmark (20971500 calls in 2.253 s)
Time: 103.6 ns 95% CI 99.39 ns - 107.7 ns (n=20)
Garbage: 0.7629 ns (n=7 sweeps measured)
res1: Boolean = true
scala> 20971500 > 10485740
res2: Boolean = true
scala> th.pbench { meth1(uc1) }
Benchmark (41943020 calls in 4.148 s)
Time: 94.70 ns 95% CI 90.66 ns - 98.74 ns (n=20)
Garbage: 2.480 ns (n=56 sweeps measured)
res3: Boolean = false
scala> th.pbench { meth2(uc1) }
Benchmark (83886060 calls in 1.837 s)
Time: 20.59 ns 95% CI 19.59 ns - 21.60 ns (n=20)
Garbage: 0.3099 ns (n=15 sweeps measured)
res4: Boolean = false
scala> 83886060 > 41943020
res5: Boolean = true
scala> th.pbench { meth1(uc2) }
Benchmark (10485740 calls in 1.602 s)
Time: 143.5 ns 95% CI 135.5 ns - 151.4 ns (n=20)
Garbage: 3.242 ns (n=14 sweeps measured)
res6: Boolean = false
scala> th.pbench { meth2(uc2) }
Benchmark (41943020 calls in 2.570 s)
Time: 59.27 ns 95% CI 57.19 ns - 61.35 ns (n=20)
Garbage: 0.3815 ns (n=8 sweeps measured)
res7: Boolean = false
scala> 41943020 > 10485740
res8: Boolean = true
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment