Skip to content
This repository was archived by the owner on Feb 18, 2019. It is now read-only.
This repository was archived by the owner on Feb 18, 2019. It is now read-only.

Feature request: zero overhead benchmarking #4

@bluenote10

Description

@bluenote10

Currently it is difficult to isolate setup code from the part of the code that one really wants to measure. Silly example:

proc silly(n: int) {.measure: [100, 10000, 1000000].} =
  let s = newSeq[int](n)
  let l = s.len # <-- measure just this?
  doAssert l == n

The measurement is obviously completely dominated by the setup code let s = newSeq[int](n). A work-around is to initialize data in the surrounding scope and close over the data variables. But this prevents to parametrize the benchmark and there seems to be an overhead of copying the data to the benchmark. There is also the general overhead:

proc overhead(b: bool) {.measure: [true].} =
  doAssert b

which is ~4 cycles for me.

What about the following API:

proc silly(n: int): Measure {.measure: [100, 10000, 1000000].} =
  let s = newSeq[int](n)
  timed:
    let l = s.len # <-- measure just this?
  doAssert l == n

Where timed is a template that internally measure the time/cycles before and after executing its body and updating result with the corresponding time/cycle deltas. This would allow to separate the setup & optimization prevention code from the actual benchmark code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions