473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to massure cpu time to evalute sorting algorithems

hi
I am writing a program that have some sorting algorithms, and i want to compare between this algorithms and i need the code in C++ to see how much the cpu take time to execute each algorithm.
Jan 10 '10 #1
3 2592
weaknessforcats
9,208 Expert Mod 8TB
Easier said than done. It depends on a) the CPU, b) what else is running on the machine, c) buffering, d) randomness of the data, e) the operating system, f) number of cores, etc...

You might do some research on profiling. You may find that your measurement comes form controlled executions rather than direct CPU usage measurements.
Jan 10 '10 #2
The time ? if that's what you're looking for, include time.h then declare two
variables, with clock_t as type, just like the following

Expand|Select|Wrap|Line Numbers
  1. clock_t start,end;  
  2.  
  3.   start = clock(); //mark the beginnning  
  4.   function();  
  5.   end = clock();  // mark the end 
  6.   printf("Time elapsed : %ld ms.",(end-start)*1000/CLOCKS_PER_SEC);
  7.  
CLOCKS_PER_SEC is a constant that will let you know how many clocks your configuration (hardware+software) generates per second.

I hope this helps
Jan 13 '10 #3
Banfa
9,065 Expert Mod 8TB
Unfortunately on todays multicore processors and multitasking operating systems that doesn't work.

clock() returns the number of clock ticks elapsed since the program was launched. On such an operating sytem your algorithm ends up measuring not just how long the algorithm took to run but also any operating system activity and the runtime of any other programs that received processor time while your program was running.

If you want to know how long a particular algorithm (or function) is taking to run in a program probably your best bet is to get a decent profiler.

Some operating systems (including Windows) can provide information on how much processor time a specific process (or thread) has had in which case writing a small test program for the algorithm/function and then accessing the OS stats might be of use.
Jan 13 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
3
by: Edg Bamyasi | last post by:
This Is A Late Cross Post from comp.lang.python. It seems the mistery is deeper then i expected. What is the running time of conactination on character strings. i.e. >> joe="123" >>...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
68
by: Roman Ziak | last post by:
Hello, I just downloaded MS Visual Studio 2005 Express Beta. When I tried to compile existing valid project, I get a lot of warnings like 'sprintf' has been deprecated, 'strcpy' has been...
5
by: Al | last post by:
Hi When I add item first time to a ListViewItem control it does is very quick.But when I remove all item and add again it takes much longer. Can anyone tell me why is that and How I can improve the...
20
by: Ajay Bathija | last post by:
Hi: I am new to this forum. If I am not through in my explanation then please let me know. I need help in figuring out how I can accomplish the following. I am using VB.net for the front...
8
by: sara | last post by:
Hi - I have looked at all posts and tried both Allen Browne's Report Sorting at run Time ( Select Case Forms!frmChooseSort!grpSort Case 1 'Name Me.GroupLevel(0).ControlSource = "LastName"...
11
by: Trent | last post by:
Running this I see that on first run, both bubble and selection sort have 9 sort counts while insertion sort has ZERO. With a sorted list, should this be ZERO for all? Also bsort and Ssort have...
7
by: christery | last post by:
Anyone got a clue to why ther is a T between date and time in the "formatted for sorting" or whatewer they call it, and a Z at the end after seconds- got it fixed for my cobol programmer by...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.