Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculating the overhead includes overhead of calculating overhead #1

Open
jonadv opened this issue May 17, 2021 · 0 comments
Open

Comments

@jonadv
Copy link

jonadv commented May 17, 2021

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
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant