Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- long seed = XorshiftGenerator.randomSeed();
- Xorshift64Generator rand1 = new Xorshift64Generator(seed);
- Xorshift64Generator rand2 = new Xorshift64Generator(seed);
- boolean[] bools = new boolean[1 << 20];
- long t0,t1;
- t0 = System.nanoTime();
- for(int i = 0; i < (1 << 20); i++){
- bools[i] = rand1.nextBoolean(); // <- return ( next() & 1 ) != 0;
- }
- t1 = System.nanoTime();
- System.out.println("Uncached time lapse: " + (t1 - t0)/1000);
- t0 = System.nanoTime();
- for(int i = 0; i < (1 << 20); i++){
- bools[i] = rand2.nextBooleanCached(); // <- cached version
- }
- t1 = System.nanoTime();
- System.out.println("Cached time lapse: " + (t1 - t0)/1000);
- System.out.println();
- System.out.println("Testing if the order matters..:");
- seed = XorshiftGenerator.randomSeed();
- rand1 = new Xorshift64Generator(seed);
- rand2 = new Xorshift64Generator(seed);
- t0 = System.nanoTime();
- for(int i = 0; i < (1 << 20); i++){
- bools[i] = rand1.nextBooleanCached();
- }
- t1 = System.nanoTime();
- System.out.println("Cached time lapse: " + (t1 - t0)/1000);
- t0 = System.nanoTime();
- for(int i = 0; i < (1 << 20); i++){
- bools[i] = rand2.nextBoolean();
- }
- t1 = System.nanoTime();
- System.out.println("Uncached time lapse: " + (t1 - t0)/1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement