-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarkTester.scala
57 lines (53 loc) · 2.97 KB
/
BenchmarkTester.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
import java.lang.reflect.Type
import java.util.Locale
object BenchmarkTester {
def main(args: Array[String]) {
val total = 67108864 // 2^26
var inputs = new Array[Int](total)
println("Populating list of inputs...")
for (i <- 0 until total) { //test every number from 0 to total
inputs(i) = i
}
/* Uncomment the test(s) you want to run */
println("Benchmarking using Array input...")
print("Duration of divideByTwo: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.divideByTwo(_), inputs) + "ms\n")
print("Duration of recursiveDivideByTwo: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.recursiveDivideByTwo(_), inputs) + "ms\n")
print("Duration of checkAll: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.checkAll(_), inputs) + "ms\n")
print("Duration of checkNextPower: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.checkNextPower(_), inputs) + "ms\n")
print("Duration of linearSearch: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.linearSearch(_), inputs) + "ms\n")
print("Duration of binarySearch: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.binarySearch(_), inputs) + "ms\n")
print("Duration of countOnes: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.countOnes(_), inputs) + "ms\n")
print("Duration of shiftRight: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.shiftRight(_), inputs) + "ms\n")
print("Duration of decrementAndCompare: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.decrementAndCompare(_), inputs) + "ms\n")
println("Benchmarking using Generated input...")
print("Duration of divideByTwo: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.divideByTwo(_), (i: Int) => i, total) + "ms\n")
print("Duration of recursiveDivideByTwo: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.recursiveDivideByTwo(_), (i: Int) => i, total) + "ms\n")
print("Duration of checkAll: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.checkAll(_), (i: Int) => i, total) + "ms\n")
print("Duration of checkNextPower: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.checkNextPower(_), (i: Int) => i, total) + "ms\n")
print("Duration of linearSearch: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.linearSearch(_), (i: Int) => i, total) + "ms\n")
print("Duration of binarySearch: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.binarySearch(_), (i: Int) => i, total) + "ms\n")
print("Duration of countOnes: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.countOnes(_), (i: Int) => i, total) + "ms\n")
print("Duration of shiftRight: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.shiftRight(_), (i: Int) => i, total) + "ms\n")
print("Duration of decrementAndCompare: ")
print(Benchmarker.benchmark[Int, Boolean](IsPowerOfTwo.decrementAndCompare(_), (i: Int) => i, total) + "ms\n")
}
}