Skip to content

Instantly share code, notes, and snippets.

View apangin's full-sized avatar

Andrei Pangin apangin

View GitHub Profile
@apangin
apangin / Queue.java
Last active August 29, 2015 14:22
Capacity field vs. array length
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 org.openjdk.jmh.annotations.Threads;
import sun.misc.Unsafe;
@apangin
apangin / constants.txt
Created June 3, 2015 23:48
HotSpot VMStructs
const int ASSERT = 0
const int STACK_BIAS = 0
const int oopSize = 8
const int LogBytesPerWord = 3
const int BytesPerWord = 8
const int BytesPerLong = 8
const int LogKlassAlignmentInBytes = 3
const int ageTable::table_size = 16
const int BarrierSet::ModRef = 0
const int BarrierSet::CardTableModRef = 1
package bench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@State(Scope.Thread)
public class InliningBenchmark {
static volatile int value = 20;
@apangin
apangin / BenchBase.java
Created October 18, 2015 22:37
DB connection pool benchmark
/*
* Copyright (C) 2014 Brett Wooldridge, Andrei Pangin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@apangin
apangin / LZ4Array.java
Created January 14, 2016 13:54
Java LZ4 benchmark
package lz4;
import static lz4.LZ4Common.*;
public class LZ4Array {
private static long getLong(byte[] b, int p) {
return (b[p] & 0xffL)
| (b[p + 1] & 0xffL) << 8
| (b[p + 2] & 0xffL) << 16
package bench;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@State(Scope.Benchmark)
public class ListIndexOf {
private static final Random random = new Random(0);
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
for (;;) {
Thread.sleep(10);
System.out.println(System.currentTimeMillis() - start);
}
}
@apangin
apangin / ArrayGet.java
Created April 1, 2016 11:41
Array Getter benchmark
package bench;
import org.openjdk.jmh.annotations.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.stream.IntStream;
@State(Scope.Benchmark)
public class ArrayGet {
package bench;
import org.openjdk.jmh.annotations.*;
import java.util.Random;
@State(Scope.Benchmark)
public class Blend {
int foreground = new Random(0).nextInt();
@apangin
apangin / bytecodes.txt
Created June 26, 2016 03:41
Length of Java Bytecodes
opcode length name
-----------------------------
0 1 nop
1 1 aconst_null
2 1 iconst_m1
3 1 iconst_0
4 1 iconst_1
5 1 iconst_2
6 1 iconst_3
7 1 iconst_4