// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; import org.junit.Test; /** * Compares alternative ways of appending strings * * @author bratseth */ public class StringAppendMicroBenchmarkTest { private static abstract class Benchmark { private int repetitions=10000000; public void execute() { System.out.println("Executing benchmark '" + getName() + "' ..."); append(100000); // warm-up long start=System.currentTimeMillis(); append(repetitions); long duration=System.currentTimeMillis()-start; System.out.println("Completed " + repetitions + " repetitions in " + duration + " ms\n"); } private int append(int repetitions) { String prefix="hello"; int totalSize=0; for (int i=0; i