#Files being closed by benchmark

12 messages · Page 1 of 1 (latest)

fervent osprey
#

I might be wrong but won't your benches get run multiple times?

#

After the first run, the closer would already be closer

#

Are you invoking with -benchtime=1x?

Altho for very fast runs, it might give very varying results between runs, so if you want consistent numbers you'll probably need to change the way you pass inputs as to avoid sharing closers

verbal fulcrum
#

don't apply side effects to test or it's members

#

I usually just put a string and call os.Open inside the benchmark or test

#

you can use b.ResetTimer() after os.Open so it doesn't benchmark os.Open itself

#

You could also not worry about it and don't close anything, your OS close files for you when you exit

#

make the field func(testing.TB) io.Reader

#

Aren't you apply side effects to test members right here ?

defer tc.Input.Close()

#

you can close it if you want

#

but not whatever is inside test

#

you just can't modify the test array since it's shared accross tests, benchmarks and benchmark reruns