Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.codelexems;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class StringEqualsBenchmark {
String s1;
String s2;
public void setup() throws Exception{
s1 = getRandom();
s2 = getRandom();
String getRandom(){
Random random = new Random();
IntStream firstStream = random.ints('a', 'z' + 1).limit(10_000);
IntStream secondStream = random.ints('A', 'Z' + 1).limit(10_000);
List<Integer> list = IntStream.concat(firstStream,secondStream).boxed()
.collect(Collectors.collectingAndThen(Collectors.toList(),l->{Collections.shuffle(l); return l;}));
StringBuilder stringBuilder = new StringBuilder();
for (int anInt : list) {
return stringBuilder.toString();
public boolean withLowerCase(){
return s1.toLowerCase().equals(s2.toLowerCase());
public boolean withIgnoreCases(){
return s1.equalsIgnoreCase(s2);
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder()
Runner runner = new Runner(options);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.