1   /*
2    * Created on Mar 20, 2004
3    * 
4    * To change the template for this generated file go to Window - Preferences -
5    * Java - Code Generation - Code and Comments
6    */
7   package nl.tudelft.simulation.jstats.distributions;
8   
9   import nl.tudelft.simulation.jstats.streams.Java2Random;
10  import nl.tudelft.simulation.jstats.streams.StreamInterface;
11  
12  /***
13   * @author Peter Jacobs
14   * 
15   * To change the template for this generated type comment go to Window -
16   * Preferences - Java - Code Generation - Code and Comments
17   */
18  public final class DistributionsBenchmark
19  {
20  	/***
21  	 * constructs a new StreamBenchmark
22  	 */
23  	private DistributionsBenchmark()
24  	{
25  		super();
26  		//unreachable code
27  	}
28  
29  	/***
30  	 * benchmarks a stream by drawing 1000000 double values
31  	 * 
32  	 * @param continuousDistribution the continuousDistribution to test
33  	 * @return the execution time in milliseconds
34  	 */
35  	public static long benchmark(final DistContinuous continuousDistribution)
36  	{
37  		long startTime = System.currentTimeMillis();
38  		for (int i = 0; i < 1000000; i++)
39  		{
40  			continuousDistribution.draw();
41  		}
42  		return System.currentTimeMillis() - startTime;
43  	}
44  
45  	/***
46  	 * benchmarks a stream by drawing 1000000 double values
47  	 * 
48  	 * @param discreteDistribution the discreteDistribution to test
49  	 * @return the execution time in milliseconds
50  	 */
51  	public static long benchmark(final DistDiscrete discreteDistribution)
52  	{
53  		long startTime = System.currentTimeMillis();
54  		for (int i = 0; i < 1000000; i++)
55  		{
56  			discreteDistribution.draw();
57  		}
58  		return System.currentTimeMillis() - startTime;
59  	}
60  
61  	/***
62  	 * executes the benchmark
63  	 * 
64  	 * @param args the commandline arguments
65  	 */
66  	public static void main(final String[] args)
67  	{
68  		StreamInterface stream = new Java2Random();
69  		System.out.println("DistBernoulli : "
70  				+ DistributionsBenchmark.benchmark(new DistBernoulli(stream,
71  						1.0)));
72  		System.out.println("DistBeta : "
73  				+ DistributionsBenchmark.benchmark(new DistBeta(stream, 1.0,
74  						2.0)));
75  		System.out.println("DistBinomial : "
76  				+ DistributionsBenchmark.benchmark(new DistBinomial(stream, 3L,
77  						0.23)));
78  		System.out.println("DistConstant : "
79  				+ DistributionsBenchmark.benchmark(new DistConstant(stream,
80  						0.23)));
81  		System.out.println("DistDiscreteConstant : "
82  				+ DistributionsBenchmark.benchmark(new DistDiscreteConstant(
83  						stream, 14)));
84  		System.out.println("DistDiscreteUniform : "
85  				+ DistributionsBenchmark.benchmark(new DistDiscreteUniform(
86  						stream, 0, 1)));
87  		System.out.println("DistErlang : "
88  				+ DistributionsBenchmark.benchmark(new DistErlang(stream, 1,
89  						0.1)));
90  		System.out.println("DistExponential : "
91  				+ DistributionsBenchmark.benchmark(new DistExponential(stream,
92  						0.1)));
93  		System.out.println("DistGamma : "
94  				+ DistributionsBenchmark.benchmark(new DistGamma(stream, 0.1,
95  						0.5)));
96  		System.out.println("DistGeometric : "
97  				+ DistributionsBenchmark.benchmark(new DistGeometric(stream,
98  						0.1)));
99  		System.out.println("DistLogNormal : "
100 				+ DistributionsBenchmark.benchmark(new DistLogNormal(stream,
101 						10, 1.0)));
102 		System.out.println("DistNegBinomial : "
103 				+ DistributionsBenchmark.benchmark(new DistNegBinomial(stream,
104 						1, 0.1)));
105 		System.out.println("DistNormal : "
106 				+ DistributionsBenchmark.benchmark(new DistNormal(stream, 1,
107 						0.1)));
108 		System.out.println("DistPearson5 : "
109 				+ DistributionsBenchmark.benchmark(new DistPearson5(stream, 1,
110 						0.1)));
111 		System.out.println("DistPearson6 : "
112 				+ DistributionsBenchmark.benchmark(new DistPearson6(stream, 1,
113 						0.1, 0.5)));
114 		System.out.println("DistPoisson : "
115 				+ DistributionsBenchmark.benchmark(new DistPoisson(stream,
116 						23.21)));
117 		System.out.println("DistTriangular : "
118 				+ DistributionsBenchmark.benchmark(new DistTriangular(stream,
119 						1, 4, 9)));
120 		System.out.println("DistUniform: "
121 				+ DistributionsBenchmark
122 						.benchmark(new DistUniform(stream, 0, 1)));
123 		System.out.println("DistWeibull: "
124 				+ DistributionsBenchmark.benchmark(new DistWeibull(stream, 0.4,
125 						1.5)));
126 
127 
128 	}
129 }