Advertisement

time...to multiply

Started by August 10, 2001 09:13 PM
1 comment, last by RolandofGilead 23 years, 6 months ago
anyone know offhand how long the C/C++ function exp() takes compared to a recursive function? anyone know offhand how long the C/C++ function exp() takes when it''s a power of two compared to multiplying only? I know I know, measure time before and after, but I''m always interested in seeing how mid to high level language functions are transformed into low level machine code Create.
You can make MSVC, and most other compilers too, generate a text file with the asm code in it that you can review, for both debug and release builds. Whenever I''m curious I just pop open the Disammebly debug window.

...
You can use the RTDSC op code on modern pentiums to time how long anything takes in CPU clock ticks. Keep in mind that this will include any time spent in another thread if you get swapped out and when the CPU handles any interrupts.

Recursion generally blows, it''s usefulness is in the high-level trees, not in algorithms.

  __int64 __declspec( naked )  RDTSC()	{	_asm		{		//Prolog		push   ebp      mov    ebp, esp      sub    esp, __LOCAL_SIZE      		//Get CPU Ticks		//xor    eax, eax		//xor    ebx, ebx		//xor    ecx, ecx		//xor    edx, edx		_emit  0x0f				// RDTSC returns cpu ticks in edx:eax		_emit  0x31		//Epilog      mov    esp, ebp      pop    ebp		ret		}	}  


Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Thanks Magmai Kai Holmlor, I can''t believe I forgot about
compiling to assembly(as my compiler calls it). I use to
know a little assembly, then I found C, then C++.

Create.

This topic is closed to new replies.

Advertisement