@@ -0,0 +1,2855 @@
+/**%0A * Copyright 2010 - 2017 JetBrains s.r.o.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage jetbrains.exodus.benchmark.util;%0A%0Aimport jetbrains.exodus.util.StringInterner;%0Aimport org.openjdk.jmh.annotations.*;%0A%0Aimport java.util.Random;%0Aimport java.util.concurrent.TimeUnit;%0A%0A@State(Scope.Thread)%0A@OutputTimeUnit(TimeUnit.SECONDS)%0Apublic class JMHStringInternerMacroBenchmark %7B%0A%0A    private static final int STRINGS_COUNT = 200000;%0A    private final StringInterner xdInterner = StringInterner.newInterner(47973);%0A%0A    private final String%5B%5D strings = new String%5BSTRINGS_COUNT%5D;%0A    private final int%5B%5D indices = new int%5BSTRINGS_COUNT%5D;%0A%0A    @Setup%0A    public void prepare() %7B%0A        for (int i = 0; i %3C STRINGS_COUNT; ++i) %7B%0A            strings%5Bi%5D = %220000000000%22 + i;%0A        %7D%0A        Random rng = new Random(3135);%0A        for (int i = 0; i %3C STRINGS_COUNT; i++) %7B%0A            indices%5Bi%5D = rng.nextInt(STRINGS_COUNT);%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(iterations = 4, time = 1)%0A    @Measurement(iterations = 8, time = 1)%0A    @Fork(value = 5, jvmArgsAppend = %22-XX:StringTableSize=43853%22)%0A    public int jdkInternDefault() %7B%0A        int result = 0;%0A        for (int index : indices) %7B%0A            result += strings%5Bindex%5D.intern().charAt(10);%0A            String again = strings%5BSTRINGS_COUNT - index - 1%5D.intern();%0A            result += again.charAt(again.length() - 1);%0A        %7D%0A        return result;%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(iterations = 4, time = 1)%0A    @Measurement(iterations = 8, time = 1)%0A    @Fork(value = 5, jvmArgsAppend = %22-XX:StringTableSize=1024099%22)%0A    public int jdkIntern() %7B%0A        int result = 0;%0A        for (int index : indices) %7B%0A            result += strings%5Bindex%5D.intern().charAt(10);%0A            String again = strings%5BSTRINGS_COUNT - index - 1%5D.intern();%0A            result += again.charAt(again.length() - 1);%0A        %7D%0A        return result;%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(iterations = 4, time = 1)%0A    @Measurement(iterations = 8, time = 1)%0A    @Fork(5)%0A    public int xdIntern() %7B%0A        int result = 0;%0A        for (int index : indices) %7B%0A            result += xdInterner.doIntern(strings%5Bindex%5D).charAt(10);%0A            String again = strings%5BSTRINGS_COUNT - index - 1%5D.intern();%0A            result += again.charAt(again.length() - 1);%0A        %7D%0A        return result;%0A    %7D%0A%7D%0A

add JMHStringInternerMacroBenchmark