This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright The async-profiler authors | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.concurrent.ThreadLocalRandom; | |
import java.util.stream.Stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright Andrei Pangin | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
import java.util.ArrayList; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int hash(String... args) { | |
if (args != null) { | |
switch (args.length) { | |
case 1: | |
return 31 + Objects.hashCode(args[0]); | |
case 2: | |
return 961 + Objects.hashCode(args[0]) * 31 + args[1].hashCode(); | |
case 3: | |
return 29791 + Objects.hashCode(args[0]) * 961 + args[1].hashCode() * 31 + args[2].hashCode(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import java.util.concurrent.atomic.LongAdder; | |
public class ReaderThread extends Thread { | |
private static final LongAdder ops = new LongAdder(); | |
interface Reader extends Serializable { | |
boolean advanceTo(int docId); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bench; | |
import com.auth0.jwt.JWT; | |
import com.auth0.jwt.JWTCreator; | |
import com.auth0.jwt.algorithms.Algorithm; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import java.util.HashMap; | |
public class JwtToken { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sun.misc.Unsafe; | |
import java.io.IOException; | |
import java.lang.reflect.Field; | |
import java.nio.ByteBuffer; | |
import java.nio.ByteOrder; | |
import java.nio.channels.FileChannel; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bench; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
import java.util.Arrays; | |
import java.util.concurrent.ThreadLocalRandom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bench; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
import java.util.HashMap; | |
import java.util.Map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
// See https://twitter.com/tagir_valeev/status/1402089474805354499 | |
public class StringBuilderHash { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.concurrent.locks.LockSupport; | |
import java.util.stream.StreamSupport; | |
public class ParallelStream { | |
public static int[] process(Iterable<Integer> iterable) { | |
return StreamSupport.stream(iterable.spliterator(), true) | |
.mapToInt(i -> { | |
LockSupport.parkNanos(1_000_000); |
NewerOlder