Skip to content

Instantly share code, notes, and snippets.

@nremond
Created February 2, 2013 23:20
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 nremond/4699699 to your computer and use it in GitHub Desktop.
Save nremond/4699699 to your computer and use it in GitHub Desktop.
String interpolation benchmark
import scala.testing.Benchmark
val a="aaa"
val b="bbb"
val c="ccc"
object Format1 extends Benchmark {
def run = String.format("%s - %s - %s\n", a, b, c)
}
Format1.multiplier = 10000
Format1.runBenchmark(20)
object Interp1 extends Benchmark {
def run = s"$a - $b - $c\n"
}
Interp1.multiplier = 10000
Interp1.runBenchmark(20)
object Interp2 extends Benchmark {
def run = raw"$a - $b - $c" +"\n"
}
Interp2.multiplier = 10000
Interp2.runBenchmark(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment