• Josh Bleecher Snyder's avatar
    testing: only call ReadMemStats if necessary when benchmarking · 948b21a3
    Josh Bleecher Snyder authored
    When running benchmarks with -cpuprofile,
    the entire process gets profiled,
    and ReadMemStats is surprisingly expensive.
    Running the sort benchmarks right now with
    -cpuprofile shows almost half of all execution
    time in ReadMemStats.
    
    Since ReadMemStats is not required if the benchmark
    does not need allocation stats, simply skip it.
    This will make cpu profiles nicer to read
    and significantly speed up the process of running benchmarks.
    It might also make sense to toggle cpu profiling
    on/off as we begin/end individual benchmarks,
    but that wouldn't get us the time savings of
    skipping ReadMemStats, so this CL is useful in itself.
    
    Change-Id: I425197b1ee11be4bc91d22b929e2caf648ebd7c5
    Reviewed-on: https://go-review.googlesource.com/36791
    Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
    948b21a3
sub_test.go 14.1 KB