Skip to content

Instantly share code, notes, and snippets.

View omsn's full-sized avatar

Korbi Schmid omsn

  • Oracle
  • Austin, TX
View GitHub Profile
final class MyFinalClass {
private final Map<Long, Object> cache;
public MyClassFixed() {
cache = new HashMap<>();
}
// final method
public Object get(long id) {
class MyClassOptimized {
private final Map<Long, Object> cache;
public MyClassFixed() {
cache = new HashMap<>();
}
// non-virtual method
public final Object get(long id) {
class MyClassFixed {
private final Map<Long, Object> cache;
public MyClassFixed() {
// won't compile without this line
cache = new HashMap<>();
}
public Object get(long id) {
class MyClass {
private Map<Long, Object> cache;
public Object get(long id) {
return cache.get(id);
}
}
@omsn
omsn / touch.py
Created May 13, 2013 02:22
touch dependencies in Makefile bottom-up to avoid rebuild
import os
for d in ["configure", "Makefile", "lib.so"]:
os.system("touch " + d)
@omsn
omsn / Makefile
Created May 13, 2013 02:11
example Makefile to build a GNU Autoconf based external library
LIB = my-lib
all: $(LIB)/lib.so
$(LIB)/lib.so: $(LIB)/Makefile
@cd $(LIB); make;
$(LIB)/Makefile: $(LIB)/configure
@cd $(LIB); ./configure
@omsn
omsn / loop.java
Created February 2, 2013 19:59
simple loop
double[] array = new double[LEN];
for (int j = 0; j < array.length; j++) {
array[j] = Math.log(j);
}
public void test() {
final int ROUNDS = 10;
long a1 = 0, a2 = 0, a3 = 0, t;
double[] array = new double[8388608];
for (int i = 0; i < ROUNDS; i++) {
t = System.currentTimeMillis();
attempt1(array);
a1 += System.currentTimeMillis() - t;
@omsn
omsn / attempt3.java
Last active December 11, 2015 22:28
class ForEach extends RecursiveAction {
private double[] array;
private int from;
private int to;
// you can fine-tune this,
// should be sth between 100 and 10000
public final static int TASK_LEN = 5000;
@omsn
omsn / attempt2.java
Last active December 11, 2015 22:28
public void attempt2(final double[] array) {
ExecutorService exec = Executors.newFixedThreadPool(NTHREADS - 1);
final int segmentLen = array.length / NTHREADS;
int offset = 0;
for (int i = 0; i < NTHREADS - 1; i++) {
final int from = offset;
final int to = offset + segmentLen;
exec.execute(new Runnable() {
@Override