Path: blob/master/test/micro/org/openjdk/bench/java/lang/StringReplace.java
41161 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package org.openjdk.bench.java.lang;2425import org.openjdk.jmh.annotations.*;26import java.util.concurrent.TimeUnit;2728@BenchmarkMode(Mode.AverageTime)29@OutputTimeUnit(TimeUnit.NANOSECONDS)30@State(Scope.Benchmark)31public class StringReplace {3233public String slat1 = new String("java.lang.String");34public String sutf16 = new String("\u1D36\u1D43\u1D5B\u1D43 \uFF11\uFF13");3536@Benchmark37public String replace0x1_1_Latin1() {38return slat1.replace("Z", "z");39}4041@Benchmark42public String replace1x1_0_Latin1() {43return slat1.replace("g", "");44}4546@Benchmark47public String replace1x1_1_Latin1() {48return slat1.replace("g", "k");49}5051@Benchmark52public String replace1x1_2_Latin1() {53return slat1.replace("g", "th");54}5556@Benchmark57public String replace2x1_0_Latin1() {58return slat1.replace(".", "");59}6061@Benchmark62public String replace2x1_1_Latin1() {63return slat1.replace(".", "/");64}6566@Benchmark67public String replace2x1_2_Latin1() {68return slat1.replace(".", "::");69}7071@Benchmark72public String replace0x1_1_UTF16() {73return sutf16.replace("\u1D36", "\u1D38\u1D3A");74}7576@Benchmark77public String replace1x1_0_UTF16() {78return sutf16.replace("\uFF11", "");79}8081@Benchmark82public String replace1x1_1_UTF16() {83return sutf16.replace("\u1D36", "\u24BF");84}8586@Benchmark87public String replace1x1_2_UTF16() {88return sutf16.replace("\uFF11", "\uFF11\uFF12");89}9091@Benchmark92public String replace2x1_0_UTF16() {93return sutf16.replace("\u1D43", "");94}9596@Benchmark97public String replace2x1_1_UTF16() {98return sutf16.replace("\u1D43", "\u1D2C");99}100101@Benchmark102public String replace2x1_2_UTF16() {103return sutf16.replace("\u1D43", "\u21DB\u21DB");104}105}106107108