Commit Graph

159 Commits

Author SHA1 Message Date
Pavol Vaskovic
be39c02001 [benchmark] Refactor numIters computation
The spaghetti if-else code was untangled into nested function that computes `iterationsPerSampleTime` and a single constant `numIters` expression that takes care of the overflow capping as well as the choice between fixed and computed `numIters` value.

The `numIters` is now computed and logged only once per benchmark measurement instead of on every sample.

The sampling loop is now just a single line. Hurrah!

Modified test to verify that the `LogParser` maintains `num-iters` derived from the `Measuring with scale` message across samples.
2018-08-31 17:17:48 +02:00
Pavol Vaskovic
46ee2a4bd8 [benchmark] Refactor sampling loop with addSample
Extracted sample saving to inner func `addSample`.
Used it to save the `oneIter` sample from `numIters` calibration when it comes out as 1 and continue the for loop to next sample.

This simplified following code that can now always measure the sample with `numIters` and save it.
2018-08-31 07:32:23 +02:00
Pavol Vaskovic
3c55e30382 [benchmark] Gardening: Documentation of numIters
Clarified the need for capping `numIters` according to the discussion at https://github.com/apple/swift/pull/17268#issuecomment-404831035

The sampling loop is a hairy piece of code, because it’s trying to reuse the calibration measurement as a regular sample, in case the computed `numIters` turns out to be 1. But it conflicts with the case when `fixedNumIters` is 1, necessitating a separate measurement in the else branch… That was a quick fix back then, but its hard to make it clean. More thinking is required…
2018-08-31 07:32:22 +02:00
Pavol Vaskovic
6e27af7142 [benchmark] Gardening: Sensibly rename variables
To make sense of this spaghetti code, let’s first use reasonable variable names:
* scale -> numIters
* elapsed_time -> time
2018-08-31 07:32:21 +02:00
Pavol Vaskovic
46bef893d0 [benchmark] Gardening: DRYer verbose log 2018-08-31 07:32:20 +02:00
Pavol Vaskovic
9c4876eabd [benchmark] Refactor to currency type Int
Removed unnecessary use of UInt64, where appropriate, following the advice from Swift Language Guide:

> Use the `Int` type for all general-purpose integer constants and variables in your code, even if they’re known to be nonnegative. Using the default integer type in everyday situations means that integer constants and variables are immediately interoperable in your code and will match the inferred type for integer literal values.
https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID324
2018-08-31 07:32:19 +02:00
Pavol Vaskovic
f017d98050 [benchmark] Refactor to report samples in μs
Moved the adjustment of `lastSampleTime` to account for the `scale` (`numIters`) and conversion to microseconds into SampleRunner’s `measure` method.
2018-08-31 07:32:18 +02:00
Pavol Vaskovic
a03aede90d [benchmark] Gardening: scale was always Int
Since the `scale` (or `numIters`) is passed to the `test.runFunction` as `Int`, the whole type-casting dance here was just silly!
2018-08-31 07:32:17 +02:00
Pavol Vaskovic
bf4a343124 [benchmark] Gardening: numSamples UInt vs Int
Type check command line argument to be non-negative, but store value in currency type `Int`.
2018-08-31 07:32:16 +02:00
Pavol Vaskovic
77dff0a1d7 [benchmark] Gardening: afterRunSleep is UInt32 2018-08-31 07:32:14 +02:00
Pavol Vaskovic
aa4b84934a [benchmark] Move stats computation to BenchResults 2018-08-31 07:32:12 +02:00
Pavol Vaskovic
0db20feda2 [benchmark] Fix index computation for quantiles
Turns out that both the old code in `DriverUtils` that computed median, as well as newer quartiles in `PerformanceTestSamples` had off-by-1 error.

It trully is the 3rd of the 2 hard things in computer science!
2018-08-31 07:32:10 +02:00
Pavol Vaskovic
5cd9f53840 [benchmark] Refactor min max median computation
We can spare 2 array passes (for min and max), if we just sort first.
2018-08-31 07:32:09 +02:00
Pavol Vaskovic
963995fa2b [benchmark] Refactor mean and stdev computation 2018-08-31 07:32:08 +02:00
Pavol Vaskovic
974994c13a [benchmark] Gardening: Timer Parasite Control
Improve conformance to Swift Naming Guidelines
https://swift.org/documentation/api-design-guidelines/#parameter-names

Removed the gross undescores and ticks from parameter names. Ticks are ectoparasites feeding on the blood. We are just measuring time and there is also no [mysterious ticking noise](http://bit.ly/TickNoise) here either…
2018-08-31 07:32:06 +02:00
Pavol Vaskovic
c1a694de30 [benchmark] Gardening: Extract constant oneSecond 2018-08-31 07:32:04 +02:00
Pavol Vaskovic
b373132548 [benchmark] Gardening: Code format class Timer 2018-08-31 07:32:03 +02:00
Pavol Vaskovic
e6cff27bab [benchmark] Gardening: Indentation of .listTests 2018-08-31 07:32:02 +02:00
swift-ci
33d95a3d22 Merge pull request #18984 from graydon/follow-my-simple-instruction 2018-08-30 16:20:29 -07:00
Pavol Vaskovic
b482a049c3 [benchmark] Gentleman yields. Don’t be a CPU hog!
It pays off of to be a nice process and yield the processor at regular intervals, to prevent having measured samples corrupted by preemptive multitasking.

When the scheduled time slice (10ms on Mac OS) is probably about to expire during the next measurement, we voluntarily yield  and resume the measurement within a fresh scheduler quantum.

This cooperative approach to multitasking improves the sample quality and robustness of the measurement process.
2018-08-28 05:37:43 +02:00
Pavol Vaskovic
7969be1c35 [benchmark] Explicitly enable static dispatch
Marking `Timer` and `SampleRunner` classes as `final` to make sure their methods use static dispatch.
2018-08-28 05:37:43 +02:00
Pavol Vaskovic
c98006c10b [benchmark] Gardening: Fixed indentation 2018-08-28 05:37:43 +02:00
Graydon Hoare
94725dff2b [benchmark] Add preliminary helper for measuring instructions executed. 2018-08-25 01:29:37 -07:00
Pavol Vaskovic
7ae5d7754c [benchmark] Report totals as a sentence
Clean up after removing bogus agregate statistics from last line of the log. It makes more sense to report the total number of executed benchmarks as a sentence that trying to fit into the format of preceding table.

Added test assertion that `run_benchmarks` return csv formatted log, as it is used to write the log into file in `log_results`.
2018-08-23 18:01:46 +02:00
Pavol Vaskovic
f29fef6b67 [benchmark] Print delim in verbose config 2018-08-16 08:11:13 +02:00
eeckstein
b042215abd Merge pull request #18211 from palimondo/fluctuation-of-the-pupil
[benchmark] Alphabetic sorting of tests and warning about incorrect use of memory option
2018-07-25 14:45:23 -07:00
Pavol Vaskovic
1a382ab775 [benchmark] Warn about incorrect --memory use 2018-07-25 08:02:28 +02:00
Pavol Vaskovic
a61a756b4d [benchmark] Fix: alphabetic sorting of tests 2018-07-25 07:45:07 +02:00
Erik Eckstein
bd43d54b99 benchmarks: Move the setup and teardown functions out of the sample loop.
This is important to minimize the runtime when many samples are taken.
2018-07-24 20:20:23 -07:00
Pavol Vaskovic
362f925e37 [benchmark][Gardening] Docs and error handling
* Improved documentation.
* Corrected`fflush` usage in `parse` error handling.
* Removed unused `passThroughArgs`.
2018-07-23 18:01:23 +02:00
Pavol Vaskovic
4ed3dcfcc5 [benchmark][Gardening] --sample-time renaming
Sample time is a better name for what was previously called `iter-scale`.
2018-07-23 17:15:54 +02:00
Pavol Vaskovic
df5ccf3e26 [benchmark][Gardening] Better naming and comments
* Restored property doc comments on `TestConfig`
* Better name for func `usage` is `getResourceUtilization`
2018-07-23 11:17:16 +02:00
Pavol Vaskovic
19613733a4 [benchmark] Log the MAX_RSS only w/ --memory flag
Printing of the MAX_RSS is now hidden behind the optional `--memory` flag.
2018-07-22 06:25:23 +02:00
Pavol Vaskovic
f89d41ad3b [benchmark] Print detailed argument help
The `--help` option now prints standard usage description with documentaion for all arguments:

````
 $ Benchmark_O --help
usage: Benchmark_O [--argument=VALUE] [TEST [TEST ...]]

positional arguments:
 TEST           name or number of the benchmark to measure

optional arguments:
 --help         show this help message and exit
 --num-samples  number of samples to take per benchmark; default: 1
 --num-iters    number of iterations averaged in the sample;
                default: auto-scaled to measure for 1 second
 --iter-scale   number of seconds used for num-iters calculation
                default: 1
 --verbose      increase output verbosity
 --delim        value delimiter used for log output; default: ,
 --tags         run tests matching all the specified categories
 --skip-tags    don't run tests matching any of the specified
                categories; default: unstable,skip
 --sleep        number of seconds to sleep after benchmarking
 --list         don't run the tests, just log the list of test
                numbers, names and tags (respects specified filters)
````
2018-07-21 22:58:44 +02:00
Pavol Vaskovic
50c79c5972 [benchmark][Gardening] Local parser error handling
In case of invalid command line arguments, there is no reasonable recovery, the `ArgumentParser` can exit the program itself.  It is therefore no longer necessary to propagate the `ArgumentError`s outside of the parser.
2018-07-21 13:30:32 +02:00
Pavol Vaskovic
f674dd5cf0 [benchmark][Gardening] Handle --help inside parser
Moved the printing of help message inside the `ArgumentParser`, which has all the necessary info.

Added test that checks the `--help` option.
2018-07-21 13:16:08 +02:00
Pavol Vaskovic
e5cbfccd22 [benchmark][Gardening] Declarative ArgumentParser
The `ArgumentParser` now has a configuration phase which specifies the supported arguments and their handling. The configured parser is then executed using the `parse` method which returns the parsed result.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
9f902866ea [benchmark][Gardening] Extracted ArgumentParser
Moved the argument parsing logic into new class `ArgumentParser`. The `checked` function is also moved to the ArgParse.swift, next to the parser.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
1841ddef5b [benchmark][Gardening] Unified argument parsing
Renamed `optionalArg` to `parseArg` because it can now also handle the positional arguments. Now all the command line arguments are handled through this function.

Minor naming improvement of the `filterTests` parameter.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
48d1558d07 [benchmark][Gardening] Nested test filter funcs
Refactored `filterTests` to use two nested functions that better reveal the underlying logic.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
bfa198b952 [benchmark][Gardening] Immutable TestConfig
The `TestConfig` is now completely immutable. Arguments that are not necessary for running benchmarks were moved inside the config initialization, which also subsumed the  `printRunInfo` function for displaying the configuration details in verbose mode.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
50575b1cff [benchmark][Gardening] Introduce PartialTestConfig
Moving towards immutable TestConfig.

The pattern used is inspired by the`PartialBenchmarkConfig` from [criterion.rs](https://github.com/japaric/criterion.rs/blob/master/src/benchmark.rs).

The idea is to have a temporary mutable struct which collects the command line arguments and is filled by the “parser” (which will be extracted later). The partial configuration is used to initialize the immutable `TestConfig`.

The optionality of the command line parameters is represented by the corresponding properties being `Optional`. (Accidentaly, all our arguments are optional… but that’s beside the point.) Null coalescing operator is used to fill in the defaults during initialization.

For some reason, the compiler found `optionalArg` calls for `tags` and `skip-tags` ambiguous, when types changed to `Set<BenchmarkCategory>?`, which was resolved by providing fully qualified key paths for them (`\PartialTestConfig.tags`).
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
b76c946fb9 [benchmark][Gardening] processArguments is init
Processing command line arguments is an integral part of `TestConfig` initialization. Make it explicit.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
f2c4262ef0 [becnhmark][Gardening] Extracted checked function 2018-07-21 01:32:40 +02:00
Pavol Vaskovic
743c7ef15f [benchmark][Gardening] Grouped argument parsing
* Extracted tag parser
* Reordered all parsing of optional arguments to be grouped together.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
2e2848b215 [benchmark][Gardening] Arguments w/ optional value
Added handling for arguments that don’t have a value (flags), or whose values are optional (they can be empty). This covers all the argument types currently used in Benchmark_O with the single `optionalArg` function.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
7d19a03dce [benchmark] Gracefully type-check attribute values
We no longer crash when the argument value parsing fails, but report an error.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
647376c55f [benchmark][Gardening] Extract optionalArg func 2018-07-21 01:32:40 +02:00
Pavol Vaskovic
371f155258 [benchmark] Exit gracefully on argument errors
Refactored to use Swift’s idiomatic error handling.
In case of invalid argument errors, the message is printed to `stderr` and we exit gracefully with error code 1. We no longer crash the app in most cases.
2018-07-21 01:32:40 +02:00
Pavol Vaskovic
dd228d7181 [benchmark][Gardening] guard benchArgs 2018-07-21 01:32:40 +02:00