473,395 Members | 1,539 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,395 software developers and data experts.

measure time eclapsed for a simple program

I ran the following code for a square matrix whose size ranges from 1x1
to 1000x1000

start=clock();
//sequential access time measurement
for (i=0;i<Msize;i++)
for(j=0;j<Nsize;j++)
{
Matrix[i]j]=1;

}
finish=clock();
duration=(double)(finish-start);

The duration is all 0 tick from matrix 1x1 to 500x500 but then it jumps
suddenly to 10000 for matrix 501x501. I have 2 questions:
1. why the sudden jump?
2. How do I get some number more accurate than 0 tick?
Ps CLOCKS_PER_SEC=1000000 for my computer

Nov 14 '05 #1
2 1816
>start=clock();
//sequential access time measurement
for (i=0;i<Msize;i++)
for(j=0;j<Nsize;j++)
{
Matrix[i]j]=1;

}
finish=clock();
duration=(double)(finish-start);

The duration is all 0 tick from matrix 1x1 to 500x500 but then it jumps
suddenly to 10000 for matrix 501x501. I have 2 questions:
1. why the sudden jump?
Just because CLOCKS_PER_SEC says the return value of clock() is in
microseconds doesn't mean the timer being used can time intervals
that short. Even systems using a sundial or something that counts
rings in trees for a clock can use CLOCKS_PER_SEC = 1000000.

Try looping and printing out the return value of clock() every time
it's different from the previous return value of clock().
My guess is you get: 0, 10000, 20000, 30000, 40000, ...

2. How do I get some number more accurate than 0 tick?
Run something that takes more time. Maybe this means slapping a
million-iteration loop around your code.
Ps CLOCKS_PER_SEC=1000000 for my computer


Gordon L. Burditt
Nov 14 '05 #2
# The duration is all 0 tick from matrix 1x1 to 500x500 but then it jumps
# suddenly to 10000 for matrix 501x501. I have 2 questions:
# 1. why the sudden jump?

If you have caches and/or virtual memory, you should expect nonlinear
responses as the problem size increases. It's a feature, not a bug, of
pretending you have more memory than you really do.

# 2. How do I get some number more accurate than 0 tick?
# Ps CLOCKS_PER_SEC=1000000 for my computer

A microsecond is a long time if everything can be kept in cache. Also even though
the ticks may be microseconds, it doesn't guarentee the clock is that accurate.

Your system might have additional profiling calls that might allow you track things
like page miss, cache reload, high resolution cpu clock, high resolution wall clock,
etc.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So basically, you just trace.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Peng Yu | last post by:
Hi, For example, there is a function which is called many times from different places in a program. I want measure how long this function runs in total. Of course, I can use gettimeofday to...
13
by: Gaijinco | last post by:
Every now and then and found two ways to resolve a problem. I try to find a way to decide which one is best (at least speed-wise) but I don't know how do I test how long those it take a program to...
6
by: Charles M. Reinke | last post by:
I'm using the function clock() to measure the run time of a program so that I can compare among several different algorithms. My code looks like: #include <stdio.h> #include <stdlib.h>...
2
by: DC | last post by:
Hi, I am looking for a simple performance benchmark, I need a report of how much time my methods need to execute - just to get an indication of where it is best to start optimizing the code. Of...
13
by: Sharon | last post by:
I need to test a performance of some code of mine. I tried using the Environment.TickCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be...
8
by: saurabh.ss | last post by:
Hi I want to measure the time required to execute a piece of code. For example, I want to know the time required to execute a given function. How do I do it within C++? I know I got to use a...
3
by: Neagu, Adrian | last post by:
Hello everybody, I try to solve the following problem: I have a python program that takes a lot of memory (>hundred Mb). I made an improvement (I hope) and I want to measure the gain (if...
2
by: Krish06 | last post by:
Hi Friends, i just need to measure the frequency and ampitude from sound.. in my pro i create a sine wave(i set freq 1000hz,amptitude200) and i passed that wave sound to my pc thru...
0
by: Gus007 | last post by:
Hi all, I was wondering how I could measure performance in my C++ program.I need to do this analysis for my university final project. Perfromance For performance I believe I could use: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.