55 */
66package fj .data ;
77
8- import fj .data .DList ;
9- import fj .data .List ;
10- import fj .data .Seq ;
11- import fj .data .Stream ;
12-
138/**
149 *
1510 * @author clintonselke
1611 */
1712public class DListPerformance {
1813
14+ static final int TOTAL_RUNS = 10 ;
15+
1916 private interface BenchmarkMethods <C > {
2017 C range (int from , int to );
2118 C append (C a , C b );
@@ -40,7 +37,7 @@ public List<Integer> unbox(List<Integer> a) {
4037 private static final BenchmarkMethods <Seq <Integer >> seqMethods = new BenchmarkMethods <Seq <Integer >>() {
4138 @ Override
4239 public Seq <Integer > range (int from , int to ) {
43- return Seq .seq (List .range (from , to ));
40+ return Seq .fromList (List .range (from , to ));
4441 }
4542 @ Override
4643 public Seq <Integer > append (Seq <Integer > a , Seq <Integer > b ) {
@@ -69,7 +66,8 @@ public List<Integer> unbox(DList<Integer> a) {
6966
7067 private static <C > double benchmark (BenchmarkMethods <C > methods ) {
7168 long msStart = System .currentTimeMillis ();
72- for (int n = 0 ; n < 10 ; ++n ) {
69+
70+ for (int runNumber = 0 ; runNumber < TOTAL_RUNS ; ++runNumber ) {
7371 final C xs = methods .range (0 , 100 );
7472 C r = xs ;
7573 for (int i = 1 ; i < 2000 ; ++i ) {
@@ -79,19 +77,22 @@ private static <C> double benchmark(BenchmarkMethods<C> methods) {
7977 for (Integer x : r2 ) {}
8078 }
8179 long msEnd = System .currentTimeMillis ();
82- return (msEnd - msStart ) / 10.0 ;
80+ return (msEnd - msStart ) / (( double ) TOTAL_RUNS ) ;
8381 }
8482
8583 public static void main (String [] params ) {
84+ System .out .println ("Starting difference list (DList) performance benchmark..." );
8685 // warm up
86+ System .out .println ("warm up..." );
8787 benchmark (listMethods );
8888 benchmark (seqMethods );
8989 benchmark (dListMethods );
9090 // actual run
91+ System .out .println ("running benchmark..." );
9192 double listTime = benchmark (listMethods );
9293 double seqTime = benchmark (seqMethods );
9394 double dListTime = benchmark (dListMethods );
94- System .out .println ("Average over 10 runs..." );
95+ System .out .println ("Average over " + TOTAL_RUNS + " runs..." );
9596 System .out .println ("List: " + listTime + "ms" );
9697 System .out .println ("Seq: " + seqTime + "ms" );
9798 System .out .println ("DList: " + dListTime + "ms" );
0 commit comments