Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.lwjgl.util.mapped.*;
- public class MappedIterTest {
- private MappedIterTest() {
- }
- @MappedType(sizeof = 4)
- public static class Mapped extends MappedObject {
- public int v;
- }
- public static void main(String[] args) {
- MappedObjectTransformer.register(Mapped.class);
- if ( MappedObjectClassLoader.fork(MappedIterTest.class, args) )
- return;
- final int SIZE = 100000;
- final int DURATION = 50;
- final int WARMUP = 5 * DURATION;
- final int BENCH = 10 * DURATION;
- Mapped foo = Mapped.malloc(SIZE);
- benchmarkView(foo, SIZE, WARMUP, BENCH);
- benchmarkView2(foo, SIZE, WARMUP, BENCH);
- benchmarkIter(foo, SIZE, WARMUP, BENCH);
- benchmarkLocal(foo, SIZE, WARMUP, BENCH);
- int[] foo2 = new int[SIZE];
- benchmarkJava(foo2, SIZE, WARMUP, BENCH);
- }
- private static void benchmarkView(Mapped foo, int SIZE, int WARMUP, int BENCH) {
- int test = 0;
- for ( int i = 0; i < WARMUP; i++ )
- test |= testView(foo, SIZE);
- long time = System.nanoTime();
- for ( int i = 0; i < BENCH; i++ )
- test |= testView(foo, SIZE);
- time = (System.nanoTime() - time) / BENCH;
- System.out.println("VIEW\n\t" + time + "ns - " + test);
- }
- private static void benchmarkView2(Mapped foo, int SIZE, int WARMUP, int BENCH) {
- int test = 0;
- for ( int i = 0; i < WARMUP; i++ )
- test |= testView2(foo, SIZE);
- long time = System.nanoTime();
- for ( int i = 0; i < BENCH; i++ )
- test |= testView2(foo, SIZE);
- time = (System.nanoTime() - time) / BENCH;
- System.out.println("VIEW2\n\t" + time + "ns - " + test);
- }
- private static void benchmarkIter(Mapped foo, int SIZE, int WARMUP, int BENCH) {
- int test = 0;
- for ( int i = 0; i < WARMUP; i++ )
- test |= testIter(foo, SIZE);
- long time = System.nanoTime();
- for ( int i = 0; i < BENCH; i++ )
- test |= testIter(foo, SIZE);
- time = (System.nanoTime() - time) / BENCH;
- System.out.println("ITER\n\t" + time + "ns - " + test);
- }
- private static void benchmarkLocal(Mapped foo, int SIZE, int WARMUP, int BENCH) {
- int test = 0;
- for ( int i = 0; i < WARMUP; i++ )
- test |= testLocal(foo, SIZE);
- long time = System.nanoTime();
- for ( int i = 0; i < BENCH; i++ )
- test |= testLocal(foo, SIZE);
- time = (System.nanoTime() - time) / BENCH;
- System.out.println("LOCAL\n\t" + time + "ns - " + test);
- }
- private static void benchmarkJava(int[] foo, int SIZE, int WARMUP, int BENCH) {
- int test = 0;
- for ( int i = 0; i < WARMUP; i++ )
- test |= testJava(foo, SIZE);
- long time = System.nanoTime();
- for ( int i = 0; i < BENCH; i++ )
- test |= testJava(foo, SIZE);
- time = (System.nanoTime() - time) / BENCH;
- System.out.println("JAVA\n\t" + time + "ns - " + test);
- }
- private static int testView(Mapped foo, int SIZE) {
- int test = 0;
- for ( int j = 0; j < SIZE; j++ ) {
- foo.view = j;
- test |= foo.v;
- }
- return test;
- }
- private static int testView2(Mapped foo, int SIZE) {
- int test = 0;
- long viewAddress;
- for ( int j = 0; j < SIZE; j++ ) {
- MappedHelper.put_view(foo, j);
- viewAddress = foo.viewAddress;
- test |= MappedHelper.iget(viewAddress + 0);
- }
- return test;
- }
- private static int testIter(Mapped foo, int SIZE) {
- int test = 0;
- for ( Mapped m : MappedObject.foreach(foo, SIZE) ) {
- test |= m.v;
- }
- return test;
- }
- private static int testLocal(Mapped foo, int SIZE) {
- int test = 0;
- long viewAddress;
- for ( int j = 0; j < SIZE; j++ ) {
- viewAddress = foo.baseAddress + j * Mapped.SIZEOF;
- test |= MappedHelper.iget(viewAddress + 0);
- }
- return test;
- }
- private static int testJava(int[] foo, int SIZE) {
- int test = 0;
- for ( int j = 0; j < SIZE; j++ ) {
- test |= foo[j];
- }
- return test;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement