gotsc icon indicating copy to clipboard operation
gotsc copied to clipboard

calculating the overhead includes overhead of calculating overhead

Open jonadv opened this issue 4 years ago • 0 comments

I'm not familiar with the GO language, but reading the TSCOverhead function, it looks like the loop also makes calculations. Again, not sure, but I think a more precise overhead might be calculated if the returned values of calling Benchstart and Benchend are stored in an array first, and differences between t0 and t1 would only be calculated after the the loop of calling Benchstart and Benchend finishes. Assuming placing the return values in an array is faster then an if-test with a substract-calculation + another substract calculation to store it. So my suggestion (or actually my question if it would be better) would be to let this function have two loops, where the first one calls the Benchstart and Benchend functions and the second loop processes the array results.

This

for i := 0; i < 100000; i++ {
	t0 = BenchStart()
	t1 = BenchEnd()
	if t1-t0 < overhead {
		overhead = t1 - t0
	}
}

would become (something like) this, if 2 seperate arrays would be used:


for i := 0; i < 100000; i++ {
	arStarts(i) = BenchStart() 'both in separate arrays, as using 2D array might be more costly (and separate arrays ensures the order of calling the functions?)
	arEnds(i) = BenchEnd()
}
for i := 0; i < 100000; i++ {
	t0 = arStarts(i)   //BenchStart() returned value
	t1 = arEnds(i)    //BenchEnd() returned value
	if t1-t0 < overhead {
		overhead = t1 - t0
	}
}

Or store in 2D array. I don't know about Go, but in some languages all arguments are evaluated first, before doing anything with it (fe VBA). It would mean that using an array won't cause any overhead (of storing value in array) at all:

for i := 0; i < 100000; i++ {
        ar(i) = (BenchStart(), BenchEnd()) 
}
for i := 0; i < 100000; i++ {
	t0 = a(i, 0)     //BenchStart() returned value
	t1 = ar(i, 1)    //BenchEnd() returned value
	if t1-t0 < overhead {
		overhead = t1 - t0
	}
}

jonadv avatar May 17 '21 11:05 jonadv