Fixed-size arrays and randomShuffle()
Chris Cain
clcain at uncg.edu
Thu May 3 08:31:16 PDT 2012
On Thursday, 3 May 2012 at 14:41:20 UTC, Vidar Wahlberg wrote:
> I tried those two as well. Still significantly slower than what
> I can achieve in Java.
You might want to post your code... I wrote this code in D:
-=-=-=-
import std.random, std.stdio, std.datetime;
void main() {
int[] arr = new int[5_000_000];
foreach(i, ref e; arr)
e = i;
StopWatch sw = AutoStart.yes;
arr.randomShuffle();
sw.stop();
writeln("Took ", sw.peek().to!("msecs", double)(), "ms");
}
-=-=-=-
And it performed _identically_ to this in Java:
-=-=-=-
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> ints = new ArrayList<>(5000);
for(int i = 0; i < 5_000_000; ++i)
ints.add(i);
long startTime = System.currentTimeMillis();
Collections.shuffle(ints);
long endTime = System.currentTimeMillis();
System.out.println("Took " + (endTime - startTime) + "ms");
}
}
-=-=-=-
More information about the Digitalmars-d-learn
mailing list