flat assembler
Message board for the users of flat assembler.

Index > Main > Calculating Clocks

Author
Thread Post new topic Reply to topic
Erikina



Joined: 06 Apr 2006
Posts: 8
Erikina
Sorry, if this has been asked - but I couldn't find an answer. If I have a chunk of assembly code - how can I tell how many CPU clocks it takes to get through it?


Thanks.
Eric.
Post 26 Jan 2007, 05:58
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
use RDTSC instruction
Post 26 Jan 2007, 07:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
Don't know what operating system you use, but note that RDTSC can be privileged instruction on some operating systems. I've read somewhere that it is privileged on some Linux systems. As for win32, I'm not aware of any version which makes it privileged though.
Post 26 Jan 2007, 08:51
View user's profile Send private message Visit poster's website Reply with quote
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
Got any code example commeted enough to be understandable to begineers? I think that this should be extremely useful for code optimization performance increase results.
Post 26 Jan 2007, 09:47
View user's profile Send private message MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Making it privileged would be pretty silly, but it's technically possible.

Note that if you time with RDTSC, you'll run into trouble on AMD64 dualcore machines if you don't limit thread affinity to one CPU. Results also tend to vary a fair amount, boosting thread+process priority and looping the code a fair amount of times helps.

Also keep in mind that for machines with power-saving features, you need to "warm up the CPU" before you start counting.

So ideally, you should study min,max,average,median runtimes of the code snippet, not just "total_cycles / total_iterations".
Post 26 Jan 2007, 09:47
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
http://en.wikipedia.org/wiki/RDTSC

Issues:

- Need to detect CPU before executing

- Multitasking / Multi-CPU (This problem can be very well bypassed using
DOS - only 1 CPU active, only 1 task Wink Wink )

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 26 Jan 2007, 11:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.