LinuxQuestions.org
Review your favorite Linux distribution.
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, 09: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, 11:49 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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 11:34 AM
Sharing CPU cycles between two systems TheStarLion Linux - General 4 04-21-2010 09:53 PM
[SOLVED] BIOS BUG: CPU#0 improperly initialized, has 317 usecs TSC skew! FIXED. harikrishnan81 Linux - Hardware 2 02-26-2008 01:51 AM
KDE Automount is using 85% of user CPU cycles iwasapenguin Linux - Software 2 11-08-2007 05:55 PM
I want to count CPU cycles used by arbitrary code JonBrant Programming 4 11-10-2006 04:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:28 AM.

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
Open Source Consulting | Domain Registration