1   /*
2    * @(#)StreamsBenchmark.java Mar 21, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.jstats.streams;
11  
12  
13  /***
14   * The StreamsBenchmark provides computational execution speed insight in the
15   * different streams.
16   * <p>
17   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
18   * University of Technology </a>, the Netherlands. <br>
19   * See for project information <a
20   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22   * License (GPL) </a>, no warranty <br>
23   * 
24   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
25   *         Jacobs </a>
26   * @version 1.0, 2004-03-18
27   * @since 1.2
28   */
29  public final class StreamsBenchmark
30  {
31  	/***
32  	 * constructs a new StreamBenchmark
33  	 */
34  	private StreamsBenchmark()
35  	{
36  		super();
37  		//unreachable code
38  	}
39  
40  	/***
41  	 * benchmarks a stream by drawing 1000000 double values
42  	 * 
43  	 * @param stream the stream to test
44  	 * @return the execution time in milliseconds
45  	 */
46  	public static long benchmark(final StreamInterface stream)
47  	{
48  		long startTime = System.currentTimeMillis();
49  		for (int i = 0; i < 10000000; i++)
50  		{
51  			stream.nextDouble();
52  		}
53  		return System.currentTimeMillis() - startTime;
54  	}
55  
56  	/***
57  	 * executes the benchmark
58  	 * 
59  	 * @param args the commandline arguments
60  	 */
61  	public static void main(final String[] args)
62  	{
63  		System.out.println("Java2Random : "
64  				+ StreamsBenchmark.benchmark(new Java2Random()));
65  		System.out.println("MersenneTwister : "
66  				+ StreamsBenchmark.benchmark(new MersenneTwister()));
67  		System.out.println("DX120Generator : "
68  				+ StreamsBenchmark.benchmark(new DX120Generator()));
69  	}
70  }