Sketcher2 source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

package com.jotuntech.sketcher.tests;
public class CacheTest {
static int[] intArray;
static short[] shortArray;
public static void main(String[] args) {
for(int i = 0; i < 1000; i++) {
test();
}
}
static private void fillArrays() {
intArray = new int[512];
shortArray = new short[512];
for(int i = 0; i < 512; ++i) {
intArray[i] = (int) Math.round(Math.random() * 511d);
shortArray[i] = (short) Math.round(Math.random() * 511d);
}
}
static private void test() {
fillArrays();
long intStart = System.nanoTime();
for(int i = 0; i < 8192; i++) {
testInt();
}
long intStop = System.nanoTime();
long intTime = intStop - intStart;
long shortStart = System.nanoTime();
for(int i = 0; i < 8192; i++) {
testShort();
}
long shortStop = System.nanoTime();
long shortTime = shortStop - shortStart;
System.err.println("Integer test: " + intTime + " ns");
System.err.println("Short test: " + shortTime + " ns");
}
static private void testInt() {
for(int i = 0; i < 512; ++i) {
intArray[i] ^= intArray[i] >> 1;
}
}
static private void testShort() {
for(int i = 0; i < 512; ++i) {
shortArray[i] ^= shortArray[i] >> 1;
}
}
}