c++ - Painfully slow function calling -
i stumbled on interesting while working in visual studio c++. calling function made set pixels screen through nested loop, x , y screen coordinates. discovered if did operations in main() function program run @ 250 frames per second, yet if moved outside function , called frame rate dropped 30 frames per second.
i did investigating test program, , replicated happened in program. below illustration of did....
if run following program....
void main() { (int = 0; < 1e9; i++) // loop billion times { 1+1; // } }
it runs in 1.6 seconds.
however, if run following code, same thing except calling outside function....
void oneplusone() { 1+1; } void main() { (int = 0; < 1e9; i++) // loop billion times { oneplusone(); // call function instead } }
it takes 18 second execute.
now, can avoid calling function , have code need in main(), makes messy , unreadable.
please tell i'm doing wrong or i've got visual studio settings set wrong or something.
the reason running slow calling function because had in debug mode. in release mode it's same. raises more questions me, why happen, anyway, help.
Comments
Post a Comment