This file contains hidden or 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.nio.ByteBuffer; | |
/** | |
* @author Ivan Babanin ([email protected]) | |
*/ | |
public class StoreFloatsInDouble { | |
public static void main(String[] args) { | |
double pack = pack(1.1f, 1.2f); | |
float[] unpack = unpack(pack); | |
System.out.println(unpack[0] + "\n" + unpack[1]); |
This file contains hidden or 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.concurrent.ForkJoinPool; | |
import java.util.concurrent.RecursiveTask; | |
/** | |
* @author Ivan Babanin ([email protected]) | |
*/ | |
public class TestFJP { | |
public static void main(String[] args) throws InterruptedException { | |
ForkJoinPool forkJoinPool = new ForkJoinPool(1); | |
forkJoinPool.submit(new Task(0)); |
This file contains hidden or 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
static { | |
// high value may be configured by property | |
int h = 127; | |
String integerCacheHighPropValue = | |
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); | |
if (integerCacheHighPropValue != null) { | |
int i = parseInt(integerCacheHighPropValue); | |
i = Math.max(i, 127); | |
// Maximum array size is Integer.MAX_VALUE | |
h = Math.min(i, Integer.MAX_VALUE - (-low) -1); |
This file contains hidden or 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
Integer x = 127; | |
System.out.println(x); // 1 | |
System.out.println(127); // 2 | |
System.out.println((Integer) 127); // 3 | |
System.out.println(new Integer(127)); // 4 |
This file contains hidden or 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
private static class LongCache { | |
private LongCache(){} | |
static final Long cache[] = new Long[-(-128) + 127 + 1]; | |
static { | |
for(int i = 0; i < cache.length; i++) | |
cache[i] = new Long(i - 128); | |
} | |
} |
This file contains hidden or 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
Field value = Integer.class.getDeclaredField("value"); | |
value.setAccessible(true); | |
value.set((Integer) 127, 0); |
This file contains hidden or 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.security.MessageDigest | |
import scala.io.Source | |
/** | |
* Created by Ivan Babanin ([email protected]) on 4/6/2014 | |
*/ | |
object MD5File { | |
def hash(filePath: String): String = | |
MessageDigest.getInstance("MD5").digest(Source.fromFile(filePath).map(_.toByte).toArray) | |
.map( 0xFF & _ ) |
This file contains hidden or 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
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> | |
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> | |
<Set name="contextPath">/</Set> | |
<Set name="virtualHosts"> | |
<Array type="java.lang.String"> | |
<Item>${YOUR_HOST_NAME}</Item> | |
<Item>${YOUR_HOST_NAME_2}</Item> | |
</Array> |
This file contains hidden or 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 org.openjdk; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; |
This file contains hidden or 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
// Compile with "-mavx2 -std=c99 -flax-vector-conversions -O3" | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <immintrin.h> | |
#include <time.h> | |
#include <sys/time.h> | |
#define TEST_ITER 10000 |
OlderNewer