Question

I have some 8086 assembly code that's going to be calling interrupts for reading and writing files. I'm using TASM to link and build my project. What options are available to me to time how long it takes to execute? I don't think counting clock cycles will work if I'm waiting on hard drive read times.

EDIT: For software recommendations, I should tell you that I'm running Windows 7.

Was it helpful?

Solution

It depends on how accurate you want to get, and how much trouble you want to go to.

You say you're calling interrupts for reading and writing files. I assume you're doing the old INT 21H interrupt functions. INT 21H Function 2Ch returns the time of day, accurate to about 5/100 seconds. See http://spike.scu.edu.au/~barry/interrupts.html#ah2c for more info.

If you can call Windows API functions, then you can call QueryPerformanceCounter to get the tick count at the beginning of the code you want to time. Call the function again afterwards, subtract the start from the end, and then divide the result by the return value from QueryPerformanceFrequency, and you've got it.

Of course, that requires doing 64-bit arithmetic.

You can call the GetSystemTime API function, passing it a SYSTEMTIME structure that gets populated. Or you can call timeGetTime, which returns the number of milliseconds since the computer was started. You have to be careful with this one, because it will roll over after 49 days.

There are probably other ways to go, too. But the simplest, if you're calling INT 21H functions, is to just use function 2CH.

OTHER TIPS

You could use profilers like oprofile or VTune or just call gettimeofday before and after your function.

I'm usually using Intel VTune performance profiler with calltree. It can show how many time was spent on your code and total time of the function.

The RDTSC instruction will give you highly accurate timing information, but does fall down a bit on modern OS's and CPUs. Have a look at the Wikipedia page for more information (or Google for RDTSC): http://en.wikipedia.org/wiki/Time_Stamp_Counter If you can, using the Win API for QueryPerformanceCounter/QueryPerformanceFrequency would be a safer bet (but also more overhead - possibly too much for your case as it sounds like you may need very fine-grained timing?).

Also check out AMD CodeAnalyst as it's free, unlike VTune.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top