File tree 1 file changed +39
-2
lines changed
test/perf/micro/scala/src/main/scala
1 file changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,51 @@ object PerfBreeze {
99
99
}
100
100
101
101
// time quicksort
102
+ def quicksort (a: Array [Double ], lo: Int , hi: Int ): Array [Double ] = {
103
+ var i, l = lo
104
+ var j = hi
105
+
106
+ def _swap (i: Int , j: Int ) = {
107
+ val tmp = a(i)
108
+ a(i) = a(j)
109
+ a(j) = tmp
110
+ }
111
+
112
+ while (i < hi) {
113
+ val pivot = a((l+ hi)>>> 1 )
114
+ while (i <= j) {
115
+ while (a(i) < pivot) i += 1
116
+ while (a(j) > pivot) j -= 1
117
+ if (i <= j) {
118
+ _swap(i, j)
119
+ i += 1
120
+ j -= 1
121
+ }
122
+ }
123
+ if (l < j) quicksort(a, l, j)
124
+ l = j
125
+ j = hi
126
+ }
127
+ a
128
+ }
129
+
130
+ /*
131
+ def checksorted(a:Array[Double]):Boolean = {
132
+ for(i <- 0 to a.length-2) {
133
+ assert(a(i) < a(i+1))
134
+ }
135
+ true
136
+ }
137
+ */
138
+
102
139
def time_quicksort () = {
103
140
var tmin = Long .MaxValue
104
141
105
142
for (i <- 1 to NITER ) {
106
143
val t1 = System .nanoTime()
107
144
for (j <- 1 to 1000 ) {
108
- val A = randomInt (5000 , ( 1 , Int . MaxValue ) )
109
- Sorting .quickSort (A .data)
145
+ val A = DenseVector .rand[ Double ] (5000 )
146
+ quicksort (A .data, 0 , 4999 )
110
147
}
111
148
val t = System .nanoTime() - t1
112
149
if (t < tmin) tmin = t
You can’t perform that action at this time.
0 commit comments