Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] Precise and invariant timing of a Maple program

Search email archive for  

[MUG] Precise and invariant timing of a Maple program
Author:    Posted: Tue, 14 May 2002 11:17:36 +0200

>> From: "pennestri"

Dear Maple User Group,
I am comparing the execution time of two
different algorithms implemented in Maple.
When I monitor the CPU time required to
execute each algorithm in Maple, I do not get
always the same answer.

I tried two different solutions (of course on the same
computer)(see below), but the values of the measured time
are not always the same.

How can I state the superiority of an algorithm
in terms of CPU time if this keeps changing
every time I execute the program?

I use Windows2000 and Maple R.6

Thanks for the answer,

Ettore Pennestrl
Universita di Roma Tor Vergata
Dipartimento di Ingegneria Meccanica
00133 Roma - Italy
e-amil: "pennestri"



-------------------------------------------------------------


> restart:
> h1:=kernelopts(cputime):
> i:=0:
> for i from 1 to 1000000 do
> i:=i+1:
> end do:
> kernelopts(cputime)-h1;

.421

> restart:
> st := time():
> i:=0:
> for i from 1 to 1000000 do
> i:=i+1:
> end do:
> time() - st;

.420
-----------------------------------------------------------------
> restart:
> h1:=kernelopts(cputime):
> i:=0:
> for i from 1 to 1000000 do
> i:=i+1:
> end do:
> kernelopts(cputime)-h1;

.431 <- This is different from .421

> restart:
> st := time():
> i:=0:
> for i from 1 to 1000000 do
> i:=i+1:
> end do:
> time() - st;

.421 <- This is different from .420

[MUG] Re: Precise and invariant timing of a Maple program
Author: Maple User Group    Posted: Fri, 17 May 2002 15:11:19 -0400

>> From: Maple User Group "maple_gr"

| >> From: "pennestri"
| Dear Maple User Group,
| I am comparing the execution time of two
| different algorithms implemented in Maple.
| When I monitor the CPU time required to
| execute each algorithm in Maple, I do not get
| always the same answer.

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: "Harold Bien" "harold.bien"
To: "maple-list"
Subject: Precise and invariant timing of a Maple program
Date: Wed, 15 May 2002 15:44:10 -0400

One thing I can think of is that you are using Windows2000 - a
multitasking operating system. Essentially it means that if you have
other programs running in the background, then depending upon those
programs' usage of the CPU the time required could vary. Unfortunately,
there is really no true method for Maple to determine how much CPU time
was spent performing your calculation, and even if you have no
"background" programs running you very well may have background
processes. For instance, Windows will once in a while flush its disk
cache - that takes time.

While it is possible for Maple to only count time that has been allotted
to Maple from Windows2000 (perhaps kernelops(cputime) takes this into
consideration), the pre-emptive multitasking nature of Windows2000 makes
it extremely difficult for Maple to really know when it has control and
when it does not.

It sounds to me like these little nuances may be causing you grief - but
it also means that the differences between your two algorithms may be so
slight as to be hidden by these variations. One potential solution,
then, would be to loop through your algorithm several times (maybe even
millions of times) to exaggerate any differences so that you can
overcome these minor variations. If you then wish to report time
required for the procedure, then you may divide by the number of
iterations.

Hope that helps.

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: "Dr Francis J. Wright" "F.J.Wright"
To: "pennestri"
Subject: Precise and invariant timing of a Maple program
Date: Thu, 16 May 2002 13:19:53 +0100

This is a standard problem with software such as computer algebra systems
and it's certainly not peculiar to Maple.

The time taken will change depending on how much information is remembered
by Maple, the need to garbage collect, the time taken swapping virtual
memory pages, competing with other processes and perhaps other users, etc.

It might help always to time each algorithm in a newly started Maple, or
always time the second run ignoring the first, depending on exactly what you
want to measure. Try to make sure the machine is in the same state each
time, so that any other load on the machine is the same (if that's an
issue). I usually time several runs and take an average.

The variability is often much worse than in your example. For less trivial
cases you probably can't expect successive timings to agree to better than
about 10% however careful you are.

Francis
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Thu, 16 May 2002 07:55:12 +0200
From: Helmut Kahovec "helmut.kahovec"
To: "maple-list" "pennestri"
Subject: Precise and invariant timing of a Maple program

Well, the execution times are different from session to session (and
even during a single session) because Maple does a lot of things in the
background, which may not always be the same. Additionally, an efficient
algorithm may become less efficient (or vice versa) when implemented in
Maple since the input is parsed and interpreted by the kernel, the
latter executing precompiled code (the so-called kernel functions) only
at certain stages of the computation.

If the execution times of two algorithms do not differ much then those
algorithms should be considered equally good when working with Maple.
However, if one of the algorithms is significantly faster than the other
then you will certainly notice that. For example, using the matrix
constructor matrix() and seq() is significantly faster than using zip()
in parallel computing with matrices:

Session 1
=========

> restart;
> N:=100:
> A:=matrix(N,N,[seq(i,i=1..N^2)]):
> B:=matrix(N,N,[seq(i,i=1..N^2)]):
> t0:=time(): zip(`*`,A,B): (time()-t0)*seconds;

1.111 seconds

> t0:=time():
> matrix(N,N,[seq(seq(A[i,j]*B[i,j],j=1..N),i=1..N)]):
> (time()-t0)*seconds;

.942 seconds

Session 2
=========

> restart;
> N:=100:
> A:=matrix(N,N,[seq(i,i=1..N^2)]):
> B:=matrix(N,N,[seq(i,i=1..N^2)]):
> t0:=time(): zip(`*`,A,B): (time()-t0)*seconds;

1.052 seconds

> t0:=time():
> matrix(N,N,[seq(seq(A[i,j]*B[i,j],j=1..N),i=1..N)]):
> (time()-t0)*seconds;

.930 seconds

Session 3
=========

> restart;
> N:=100:
> A:=matrix(N,N,[seq(i,i=1..N^2)]):
> B:=matrix(N,N,[seq(i,i=1..N^2)]):
> t0:=time(): zip(`*`,A,B): (time()-t0)*seconds;

1.061 seconds

> t0:=time():
> matrix(N,N,[seq(seq(A[i,j]*B[i,j],j=1..N),i=1..N)]):
> (time()-t0)*seconds;

.931 seconds


Kind regards,

Helmut

Previous by date: [MUG] Coupled, nonlinear ODEs., Anders Ballestad
Next by date: [MUG] 3D surface plotting from data points.
Previous thread: [MUG] Print the procedure output from dsolve,  Reuben D Budiardja
Next thread: [MUG] 3D surface plotting from data points.



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055