aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/developernotes/XMLMicroBenchmark.java
blob: 42f42853b445680e8a0755668f5296661c7431bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;

/**
 * It is what it says
 *
 * @author bratseth
 */
public class XMLMicroBenchmark {

    public void benchmark(int sizeInK) {
        System.out.println("Warming up...");
        escapeStrings(1000); // warm-up

        System.out.println("Starting benchmark...");
        long startTime=System.currentTimeMillis();
        escapeStrings(sizeInK);
        long endTime=System.currentTimeMillis();
        System.out.println("Done.\nEscaping " + sizeInK + "k strings took " + (endTime-startTime) + "ms");
    }

    private void escapeStrings(int sizeInK) {
        for (int i=0; i<1000*sizeInK; i++) {
            XML.xmlEscape("foobar" + i,true,true,'\u001f');
        }
    }

    public static void main(String[] args) {
        new XMLMicroBenchmark().benchmark(10000);
    }

}