Skip to content

Commit ae4ecbe

Browse files
committed
[benchmark] Adjust Existential workload sizes
Reduced base workloads. This allows precise measurements without the noise of accumulated error from unnecessarily long runtimes.
1 parent 94d94ee commit ae4ecbe

File tree

1 file changed

+40
-62
lines changed

1 file changed

+40
-62
lines changed

benchmark/single-source/ExistentialPerformance.swift

Lines changed: 40 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -319,132 +319,110 @@ func passExistentialTwiceTwoMethodCalls(_ e0: Existential, _ e1: Existential) ->
319319

320320
func runTestOneMethodCall<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
321321
let existential = initExistential(withType: T.self)
322-
for _ in 0 ..< N {
323-
for _ in 0 ..< 5_000_000 {
324-
if !existential.doIt() {
325-
fatalError("expected true")
326-
}
322+
for _ in 0 ..< N * 20_000 {
323+
if !existential.doIt() {
324+
fatalError("expected true")
327325
}
328326
}
329327
}
330328

331329
func runTestTwoMethodCalls<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
332330
let existential = initExistential(withType: T.self)
333-
for _ in 0 ..< N {
334-
for _ in 0 ..< 5_000_000 {
335-
if !existential.doIt() || !existential.reallyDoIt() {
336-
fatalError("expected true")
337-
}
331+
for _ in 0 ..< N * 20_000 {
332+
if !existential.doIt() || !existential.reallyDoIt() {
333+
fatalError("expected true")
338334
}
339335
}
340336
}
341337

342338
func runTestPassExistentialOneMethodCall<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
343339
let existential = initExistential(withType: T.self)
344340
let existential2 = initExistential(withType: T.self)
345-
for _ in 0 ..< N {
346-
for _ in 0 ..< 5_000_000 {
347-
if !passExistentialTwiceOneMethodCall(existential, existential2) {
348-
fatalError("expected true")
349-
}
341+
for _ in 0 ..< N * 20_000 {
342+
if !passExistentialTwiceOneMethodCall(existential, existential2) {
343+
fatalError("expected true")
350344
}
351345
}
352346
}
353347

354348
func runTestPassExistentialTwoMethodCalls<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
355349
let existential = initExistential(withType: T.self)
356350
let existential2 = initExistential(withType: T.self)
357-
for _ in 0 ..< N {
358-
for _ in 0 ..< 5_000_000 {
359-
if !passExistentialTwiceTwoMethodCalls(existential, existential2) {
360-
fatalError("expected true")
361-
}
351+
for _ in 0 ..< N * 20_000 {
352+
if !passExistentialTwiceTwoMethodCalls(existential, existential2) {
353+
fatalError("expected true")
362354
}
363355
}
364356
}
365357

366358
func runTestMutating<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
367359
var existential = initExistential(withType: T.self)
368-
for _ in 0 ..< N {
369-
for _ in 0 ..< 5_000_000 {
370-
if !existential.mutateIt() {
371-
fatalError("expected true")
372-
}
360+
for _ in 0 ..< N * 10_000 {
361+
if !existential.mutateIt() {
362+
fatalError("expected true")
373363
}
374364
}
375365
}
376366

377367
func runTestMutatingAndNonMutating<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
378368
var existential = initExistential(withType: T.self)
379-
for _ in 0 ..< N {
380-
for _ in 0 ..< 5_000_000 {
381-
let _ = existential.doIt()
382-
if !existential.mutateIt() {
383-
fatalError("expected true")
384-
}
369+
for _ in 0 ..< N * 10_000 {
370+
let _ = existential.doIt()
371+
if !existential.mutateIt() {
372+
fatalError("expected true")
385373
}
386374
}
387375
}
388376

389377
func runTestArrayOneMethodCall<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
390378
let existentialArray = initExistentialArray(withType: T.self, count: 128)
391-
for _ in 0 ..< N {
392-
for _ in 0 ..< 5_000 {
393-
for elt in existentialArray {
394-
if !elt.doIt() {
395-
fatalError("expected true")
396-
}
379+
for _ in 0 ..< N * 100 {
380+
for elt in existentialArray {
381+
if !elt.doIt() {
382+
fatalError("expected true")
397383
}
398384
}
399385
}
400386
}
401387

402388
func runTestArrayTwoMethodCalls<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
403389
let existentialArray = initExistentialArray(withType: T.self, count: 128)
404-
for _ in 0 ..< N {
405-
for _ in 0 ..< 5_000 {
406-
for elt in existentialArray {
407-
if !elt.doIt() || !elt.reallyDoIt() {
408-
fatalError("expected true")
409-
}
390+
for _ in 0 ..< N * 100 {
391+
for elt in existentialArray {
392+
if !elt.doIt() || !elt.reallyDoIt() {
393+
fatalError("expected true")
410394
}
411395
}
412396
}
413397
}
414398

415399
func runTestArrayMutating<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
416400
var existentialArray = initExistentialArray(withType: T.self, count: 128)
417-
for _ in 0 ..< N {
418-
for _ in 0 ..< 5_000 {
419-
for i in 0 ..< existentialArray.count {
420-
if !existentialArray[i].mutateIt() {
421-
fatalError("expected true")
422-
}
401+
for _ in 0 ..< N * 100 {
402+
for i in 0 ..< existentialArray.count {
403+
if !existentialArray[i].mutateIt() {
404+
fatalError("expected true")
423405
}
424406
}
425407
}
426408
}
427409

428410
func runTestArrayShift<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
429411
var existentialArray = initExistentialArray(withType: T.self, count: 128)
430-
for _ in 0 ..< N {
431-
for _ in 0 ..< 5_000 {
432-
for i in 0 ..< existentialArray.count-1 {
433-
existentialArray.swapAt(i, i+1)
434-
}
412+
for _ in 0 ..< N * 10 {
413+
for i in 0 ..< existentialArray.count-1 {
414+
existentialArray.swapAt(i, i+1)
435415
}
436416
}
437417
}
438418
func runTestArrayConditionalShift<T: Existential>(withType: T.Type, numberOfTimes N: Int) {
439419
var existentialArray = initExistentialArray(withType: T.self, count: 128)
440-
for _ in 0 ..< N {
441-
for _ in 0 ..< 5_000 {
442-
for i in 0 ..< existentialArray.count-1 {
443-
let curr = existentialArray[i]
444-
if curr.doIt() {
445-
existentialArray[i] = existentialArray[i+1]
446-
existentialArray[i+1] = curr
447-
}
420+
for _ in 0 ..< N * 10 {
421+
for i in 0 ..< existentialArray.count-1 {
422+
let curr = existentialArray[i]
423+
if curr.doIt() {
424+
existentialArray[i] = existentialArray[i+1]
425+
existentialArray[i+1] = curr
448426
}
449427
}
450428
}

0 commit comments

Comments
 (0)