aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/developernotes/Utf8MicroBencmark.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespajlib/developernotes/Utf8MicroBencmark.java
Publish
Diffstat (limited to 'vespajlib/developernotes/Utf8MicroBencmark.java')
-rw-r--r--vespajlib/developernotes/Utf8MicroBencmark.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/vespajlib/developernotes/Utf8MicroBencmark.java b/vespajlib/developernotes/Utf8MicroBencmark.java
new file mode 100644
index 00000000000..ff1ae4ce3a2
--- /dev/null
+++ b/vespajlib/developernotes/Utf8MicroBencmark.java
@@ -0,0 +1,50 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.text;
+
+/**
+ * @author <a href="mailto:balder@yahoo-inc.com">Henning Baldersheim</a>
+ * @since 5.2
+ */
+
+public class Utf8MicroBencmark {
+ public void benchmark(int sizeInK) {
+ String [] l = new String[1000];
+ for (int i=0; i < l.length; i++) {
+ l[i] = "typical ascii string" + i;
+ }
+ System.out.println("Warming up...");
+ utf8encode(l, 10000); // warm-up
+ utf8encodeFast(l, 10000);
+
+ long startTime, endTime, sum;
+ System.out.println("Starting benchmark ...");
+ startTime=System.currentTimeMillis();
+ sum = utf8encode(l, sizeInK);
+ endTime=System.currentTimeMillis();
+ System.out.println("Utf8 encoding " + sizeInK + "k strings took " + (endTime-startTime) + "ms generating " + sum + "bytes");
+ startTime=System.currentTimeMillis();
+ sum = utf8encodeFast(l, sizeInK);
+ endTime=System.currentTimeMillis();
+ System.out.println("Utf8 fast encoding " + sizeInK + "k strings took " + (endTime-startTime) + "ms generating " + sum + "bytes");
+ }
+
+ private long utf8encode(String [] l, int sizeInK) {
+ long sum = 0;
+ for (int i=0; i<1000*sizeInK; i++) {
+ sum += Utf8.toBytesStd(l[i%l.length]).length;
+ }
+ return sum;
+ }
+ private long utf8encodeFast(String [] l, int sizeInK) {
+ long sum = 0;
+ for (int i=0; i<1000*sizeInK; i++) {
+ sum += Utf8.toBytes(l[i%l.length]).length;
+ }
+ return sum;
+ }
+
+ public static void main(String[] args) {
+ new Utf8MicroBencmark().benchmark(10000);
+ }
+
+}