-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeMeasuring.kt
78 lines (71 loc) · 2.6 KB
/
timeMeasuring.kt
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.io.File
fun main() {
val n = 13
val timesBruteForcePrep = Array(n) { 0L }
val timesBruteForceAns = Array(n) { 0L }
val timesMapPrep = Array(n) { 0L }
val timesMapAns = Array(n) { 0L }
val timesSegmentTreePrep = Array(n) { 0L }
val timesSegmentTreeAns = Array(n) { 0L }
var zippedCords: Pair<List<Int>, List<Int>>
var count = 1
for (i in 0..12) {
val rectangles = getRectanglesArray(count)
val testPoints = getTestPointsArray(100000, count)
// measuring preparation time
var begin: Long = System.nanoTime()
bruteForcePrep(rectangles)
timesBruteForcePrep[i] = System.nanoTime() - begin
// measuring answering time
begin = System.nanoTime()
bruteForceAlgorithm(rectangles, testPoints)
timesBruteForceAns[i] = System.nanoTime() - begin
// measuring preparation time
begin = System.nanoTime()
zippedCords = getZippedCoordinates(rectangles)
val mapMatrix = generateMap(rectangles, zippedCords.first, zippedCords.second)
timesMapPrep[i] = System.nanoTime() - begin
// measuring answering time
begin = System.nanoTime()
getAnswersFromMap(mapMatrix, testPoints, zippedCords.first, zippedCords.second)
timesMapAns[i] = System.nanoTime() - begin
// measuring preparation time
begin = System.nanoTime()
zippedCords = getZippedCoordinates(rectangles)
val persistentTreeRoots = buildPersistentSegmentTree(rectangles, zippedCords.first, zippedCords.second)
timesSegmentTreePrep[i] = System.nanoTime() - begin
// measuring answering time
begin = System.nanoTime()
getAnswersFromPersistentTree(testPoints, persistentTreeRoots, zippedCords.first, zippedCords.second)
timesSegmentTreeAns[i] = System.nanoTime() - begin
println(count)
count *= 2
}
val path = "C:\\Users\\matve\\IdeaProjects\\Algorithms-Labs\\Lab-2\\artefacts\\times.txt"
File(path).printWriter().use { out ->
timesBruteForcePrep.forEach {
out.print("$it ")
}
out.println()
timesMapPrep.forEach {
out.print("$it ")
}
out.println()
timesSegmentTreePrep.forEach {
out.print("$it ")
}
out.println()
timesBruteForceAns.forEach {
out.print("$it ")
}
out.println()
timesMapAns.forEach {
out.print("$it ")
}
out.println()
timesSegmentTreeAns.forEach {
out.print("$it ")
}
out.println()
}
}