@@ -20,7 +20,7 @@ import LibProc
20
20
import TestsUtils
21
21
22
22
struct BenchResults {
23
- typealias T = UInt64
23
+ typealias T = Int
24
24
private let samples : [ T ]
25
25
let maxRSS : Int
26
26
let stats : Stats
@@ -37,11 +37,11 @@ struct BenchResults {
37
37
return samples [ index]
38
38
}
39
39
40
- var sampleCount : T { return UInt64 ( samples. count) }
40
+ var sampleCount : T { return samples. count }
41
41
var min : T { return samples. first! }
42
42
var max : T { return samples. last! }
43
- var mean : T { return UInt64 ( stats. mean. rounded ( ) ) }
44
- var sd : T { return UInt64 ( stats. standardDeviation. rounded ( ) ) }
43
+ var mean : T { return Int ( stats. mean. rounded ( ) ) }
44
+ var sd : T { return Int ( stats. standardDeviation. rounded ( ) ) }
45
45
var median : T { return self [ 0.5 ] }
46
46
}
47
47
@@ -235,7 +235,7 @@ struct Stats {
235
235
var variance : Double { return n < 2 ? 0.0 : S / Double( n - 1 ) }
236
236
var standardDeviation : Double { return variance. squareRoot ( ) }
237
237
238
- static func collect( _ s: inout Stats , _ x: UInt64 ) {
238
+ static func collect( _ s: inout Stats , _ x: Int ) {
239
239
Stats . runningMeanVariance ( & s, Double ( x) )
240
240
}
241
241
@@ -387,7 +387,7 @@ final class SampleRunner {
387
387
}
388
388
389
389
/// Measure the `fn` and return the average sample time per iteration (μs).
390
- func measure( _ name: String , fn: ( Int ) -> Void , numIters: Int ) -> UInt64 {
390
+ func measure( _ name: String , fn: ( Int ) -> Void , numIters: Int ) -> Int {
391
391
#if SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
392
392
name. withCString { p in startTrackingObjects ( p) }
393
393
#endif
@@ -400,13 +400,14 @@ final class SampleRunner {
400
400
name. withCString { p in stopTrackingObjects ( p) }
401
401
#endif
402
402
403
- return lastSampleTime / UInt64( numIters) / 1000
403
+ // Convert to μs and compute the average sample time per iteration.
404
+ return Int ( lastSampleTime / 1000 ) / numIters
404
405
}
405
406
}
406
407
407
408
/// Invoke the benchmark entry point and return the run time in milliseconds.
408
409
func runBench( _ test: BenchmarkInfo , _ c: TestConfig ) -> BenchResults ? {
409
- var samples = [ UInt64 ] ( repeating: 0 , count: c. numSamples)
410
+ var samples = [ Int ] ( repeating: 0 , count: c. numSamples)
410
411
411
412
// Before we do anything, check that we actually have a function to
412
413
// run. If we don't it is because the benchmark is not supported on
@@ -427,15 +428,15 @@ func runBench(_ test: BenchmarkInfo, _ c: TestConfig) -> BenchResults? {
427
428
428
429
for s in 0 ..< c. numSamples {
429
430
var scale : Int
430
- var elapsed_time : UInt64 = 0
431
+ var elapsed_time : Int = 0
431
432
if c. fixedNumIters == 0 {
432
433
elapsed_time = sampler. measure ( test. name, fn: testFn, numIters: 1 )
433
434
434
435
if elapsed_time > 0 {
435
436
let usPerSecond = 1_000_000.0 // microseconds (μs)
436
- let timePerSample = UInt64 ( c. sampleTime * usPerSecond)
437
+ let timePerSample = Int ( c. sampleTime * usPerSecond)
437
438
/// Number of iterations to make `testFn` run for the desired time.
438
- scale = Int ( timePerSample / elapsed_time)
439
+ scale = timePerSample / elapsed_time
439
440
} else {
440
441
if c. verbose {
441
442
print ( " Warning: elapsed time is 0. This can be safely ignored if the body is empty. " )
0 commit comments