-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrate with hdr histogram (#54)
## Description This fixes #40 ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. ## Minimal checklist: - [ ] I have performed a self-review of my own code - [ ] I have added `DocC` code-level documentation for any public interfaces exported by the package - [ ] I have added unit and/or integration tests that prove my fix is effective or that my feature works
- Loading branch information
Showing
9 changed files
with
258 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// Copyright (c) 2022 Ordo One AB. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
import BenchmarkSupport | ||
import Histogram | ||
|
||
@main | ||
extension BenchmarkRunner {} | ||
|
||
// swiftlint disable: attributes | ||
@_dynamicReplacement(for: registerBenchmarks) | ||
func benchmarks() { | ||
Benchmark.defaultDesiredDuration = .seconds(1) | ||
Benchmark.defaultDesiredIterations = .giga(1) | ||
|
||
Benchmark("Record", | ||
metrics: [.wallClock, .throughput] + BenchmarkMetric.memory, | ||
skip: false) { benchmark in | ||
let maxValue: UInt64 = 1_000_000 | ||
|
||
var histogram = Histogram<UInt64>(highestTrackableValue: maxValue, numberOfSignificantValueDigits: .three) | ||
|
||
let numValues = 1024 // so compiler can optimize modulo below | ||
let values = [UInt64]((0..<numValues).map { _ in UInt64.random(in: 100...1000) }) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for i in benchmark.throughputIterations { | ||
histogram.record(values[i % numValues]) | ||
} | ||
} | ||
|
||
Benchmark("Record to autoresizing", | ||
metrics: [.wallClock, .throughput] + BenchmarkMetric.memory, | ||
skip: false) { benchmark in | ||
var histogram = Histogram<UInt64>(numberOfSignificantValueDigits: .three) | ||
|
||
let numValues = 1024 // so compiler can optimize modulo below | ||
let values = [UInt64]((0..<numValues).map { _ in UInt64.random(in: 100...1000) }) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for i in benchmark.throughputIterations { | ||
histogram.record(values[i % numValues]) | ||
} | ||
} | ||
|
||
Benchmark("ValueAtPercentile", | ||
metrics: [.wallClock, .throughput], | ||
skip: false) { benchmark in | ||
let maxValue: UInt64 = 1_000_000 | ||
|
||
var histogram = Histogram<UInt64>(highestTrackableValue: maxValue, numberOfSignificantValueDigits: .three) | ||
|
||
// fill histogram with some data | ||
for _ in 0 ..< 10_000 { | ||
histogram.record(UInt64.random(in: 10...1000)) | ||
} | ||
|
||
let percentiles = [ 0.0, 25.0, 50.0, 75.0, 80.0, 90.0, 99.0, 100.0 ] | ||
|
||
benchmark.startMeasurement() | ||
|
||
for i in benchmark.throughputIterations { | ||
blackHole(histogram.valueAtPercentile(percentiles[i % percentiles.count])) | ||
} | ||
} | ||
|
||
Benchmark("Mean", | ||
metrics: [.wallClock, .throughput], | ||
skip: false) { benchmark in | ||
let maxValue: UInt64 = 1_000_000 | ||
|
||
var histogram = Histogram<UInt64>(highestTrackableValue: maxValue, numberOfSignificantValueDigits: .three) | ||
|
||
// fill histogram with some data | ||
for _ in 0 ..< 10_000 { | ||
histogram.record(UInt64.random(in: 10...1000)) | ||
} | ||
|
||
benchmark.startMeasurement() | ||
|
||
for _ in benchmark.throughputIterations { | ||
blackHole(histogram.mean) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.