CarlML

Member

142

217 Neutral

• Rank
Member

• Interests
Art
Audio
Design
Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

1. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

If I use random values between 1.0 and 1.2 there is no overflow either way and the timing results are nearly the same so the culprit was most likely infinite or infinitesimal numbers. Thanks for the input.
2. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

The numbers have to be random so that the compiler won't optimize things out. If I use random values between 0.0f and 1.0f the times are similar as in my test and the result doesn't go infinite. So overflow can't be the only reason. Edit: but they probably went infinitesimal.
3. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

Well my simple test case was enough to determine that the exponent matters in some cases. I'm not sure why but that's something. You can test yourself if oyu like. I posted the code on the first page.
4. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

I realize that work on the gpu might be different but this thread is about the pow() function in general, not the specific use case I brought up.
5. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

No specular calcualtion happens in a shader. Doing it on the cpu would be crazy.😋 As you point out, I suspect the timing difference has something to do with numbers going infiinite or infitinesimal. In a regular use case where I would use values between 20.0 and 100.0 for calucalting specular I suspect there generally would not be a big difference. To say that the exponent does not matter is wrong though because those numbers in my test don't lie. Don't be butthurt that the numbers didn't go your way.😉 In any case I appreciate the input. This was my test code, using Visual Studio 2017: float vals[100000]; for (int i = 0; i < 100000; i++) { vals[i] = random.getf(0.0f, 1000.0f); } float vall = 0.0f; timer.Start(); for (int i = 0; i < 100000; i++) { vall += pow(vals[i], 4.0f); } float tim1 = timer.End(); timer.Start(); for (int i = 0; i < 100000; i++) { vall += pow(vals[i], 400.0f); } float tim2 = timer.End(); Print(Vec3(tim1, tim2, vall));
6. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

I just did some time measurements and it seems the exponent does matter. Between 4.0 and 40.0 there was no noticable difference but as the exponent got higher there was, so it seems there is a point where the algorithm changes based on the exponent. Some results in milliseconds for doing pow() 100 000 times in c++ (including accessing an array to get a random value): 4.0: 2.977 40.0: 2.966 400.0: 4.192 4 000: 4.803 40 000: 3.872 400 000: 3.742
7. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

Thanks for the reply. Sounds good that it would generally be the same. So I guess calculating a very tight specular highlight using pow() is not more expensive than calculating a wide highlight then.
8. Is pow(val, 40.0) more expensive than pow(val, 4.0) ?

I'm curious about how the pow function works. Does the cost of the function go up linearly with the number of powers? Does it calculate val*val 40 times in pow(val, 40.0)?