LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-19-2010, 10:20 AM   #1
crudbug
LQ Newbie
 
Registered: Sep 2010
Posts: 1

Rep: Reputation: 0
How to convert TSC cpu cycles into seconds in C?


main()
{
unsigned long long tsc_start, tsc_end;
tsc_start = get_tsc();
// execute some code

tsc_end = get_tsc();
printf("Total time for execution %llu cpu cycles", tsc_end - tsc_start);
printf("Total time in seconds "); // How to compute this ?
}

static unsigned long long get_tsc()
{
unsigned long long tsc;
asm volatile ("rdtsc" : "=A" (tsc));
return tsc;
}
 
Old 09-19-2010, 12:49 PM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
maybe this is of help : http://www.unix.com/programming/81639-rdtsc-use-c.html

And please use code tags [code]your code here[/code] when posting code
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 12:34 PM
Sharing CPU cycles between two systems TheStarLion Linux - General 4 04-21-2010 10:53 PM
[SOLVED] BIOS BUG: CPU#0 improperly initialized, has 317 usecs TSC skew! FIXED. harikrishnan81 Linux - Hardware 2 02-26-2008 02:51 AM
KDE Automount is using 85% of user CPU cycles iwasapenguin Linux - Software 2 11-08-2007 06:55 PM
I want to count CPU cycles used by arbitrary code JonBrant Programming 4 11-10-2006 05:43 PM


All times are GMT -5. The time now is 04:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration