Jump to content

  • Log In with Google      Sign In   
  • Create Account

Computationally Expensive Operations


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 raydey   Members   -  Reputation: 159

Like
0Likes
Like

Posted 13 April 2009 - 09:00 AM

Hey guys, Just a quick question. I'm making a very basic program in c++ to calculate the time it takes to process a number of commands. I purposely want to push the processor as far as I can, so I was wondering whether anyone could suggest some CPU intensive operations. I already know about square root being relatively expensive, but was just wondering whether there were any others that were reasonably simple to code. Cheers Ray EDIT: Sorry, I should say, I realise graphics rendering is expensive, but it's not really what I want to code. It's a very basic command line program, for quite a pointless experiment lol

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15833

Like
0Likes
Like

Posted 13 April 2009 - 09:04 AM

If you truly want to peg your CPU, don't just repeat one trivial operation; doing a load of square roots won't really tell you anything useful.

There's a few possibilities but it depends on what exactly you are trying to measure and why.

#3 ibebrett   Members   -  Reputation: 205

Like
0Likes
Like

Posted 13 April 2009 - 09:04 AM

factor a large prime.

#4 scottrick49   Members   -  Reputation: 366

Like
0Likes
Like

Posted 13 April 2009 - 09:04 AM

you could just do a huge loop of square root calculations:


float temp = 0.0f;

for (float fValue = 1.0f; fValue < 9999999.0f; f = f + 1.0f) {
temp = sqrt(fValue);
}




or with a similar loop, you could do a bunch of memory allocations, etc. we really need more info on what you are trying to measure to give a meaningful suggestion.

#5 stonemetal   Members   -  Reputation: 288

Like
0Likes
Like

Posted 13 April 2009 - 09:09 AM

Is it a single threaded app? If so then sleep(2000) is probably good enough. If it is multi threaded and you are actually looking to calculate something then finding all primes under a million out to be a good task(especially if you don't optimize it). Heck allocate and deallocate a few chunks of memory in a tight loop can be a real time waster. Implement an atoi itoa pair and run it over some random numbers.

#6 Álvaro   Crossbones+   -  Reputation: 13373

Like
0Likes
Like

Posted 13 April 2009 - 09:15 AM

Quote:
Original post by ibebrett
factor a large prime.


Factoring primes is a trivial process. I can do it by hand very very quickly. :)



#7 ApochPiQ   Moderators   -  Reputation: 15833

Like
0Likes
Like

Posted 13 April 2009 - 11:01 AM

Quote:
Original post by scottrick49
you could just do a huge loop of square root calculations:

*** Source Snippet Removed ***

or with a similar loop, you could do a bunch of memory allocations, etc. we really need more info on what you are trying to measure to give a meaningful suggestion.



Any compiler that isn't a total sack of crap will optimize that loop out to nothingness. Any CPU that isn't a total sack of crap would also invalidate the test, because all the data will be in cache and there won't be any hits to the system bus or anything.

Like I said earlier, if you really want to peg a CPU and keep it busy, there are ways - but they are non-obvious if you don't have a fairly good understanding of modern CPU architecture (or PC architecture in general).

The real question here is why the OP wants to do this, because the answer to that question will affect exactly what kinds of time wasting tricks are actually needed.

#8 raydey   Members   -  Reputation: 159

Like
0Likes
Like

Posted 13 April 2009 - 12:21 PM

Ok, the exact reason why I want to do this, is basically because I've been assigned to design a pointless and quick experiment for a university project. It's basically using the scientific method (aim, method, results, conclusion etc) and the experiment I decided to do was "How does CPU clock speed affect the time taken to perform a large number of operations?" and test the same program out on different machines. It sounds incredibly stupid, and quite frankly it is lol, but thought this would be the easiest way to do the project without having to give out questionnaires, take surveys and all manner of crap like that.

Since, I'm also very focused on a very large C++ university project, I'm in a really C++ mood, so as long as I know what operations I want my program to perform, I can bash the code out pretty quickly.

Cheers

Ray

#9 outRider   Members   -  Reputation: 852

Like
0Likes
Like

Posted 13 April 2009 - 01:08 PM

I would suggest that you make things easy on yourself and find a machine that lets you clock the CPU in the BIOS and then repeat your test at various clock frequencies.

As for a suitable benchmark, I would personally download some medium-sized open source software and time how long it took to compile it, or how long it took to ray trace a scene, or something like that.

If you want to write the benchmark yourself however and all you want to show is the relationship between clock frequency and time it takes to do "stuff" then yeah, do a bunch of square roots or whatever and make sure the compiler doesn't optimize them out.

#10 ApochPiQ   Moderators   -  Reputation: 15833

Like
0Likes
Like

Posted 13 April 2009 - 01:21 PM

Why not just use an existing benchmark application and use its scoring output? Is there a very compelling reason to write your own?

#11 Zahlman   Moderators   -  Reputation: 1682

Like
0Likes
Like

Posted 13 April 2009 - 02:39 PM

Quote:
Original post by raydey
Ok, the exact reason why I want to do this, is basically because I've been assigned to design a pointless and quick experiment for a university project. It's basically using the scientific method (aim, method, results, conclusion etc) and the experiment I decided to do was [I basically got to pick anything trivial that I liked for this, and it turns out that implementing the system to study is harder than actually studying it]


In university? Really? If it were at the beginning of the year, for a first-year science course, I could accept it... oh, you mean you have to set the task for the students to do at the beginning of the fall 2009 courses? Then let them pick something trivial to study, and warn them that if their experiment involves implementing a system as well as studying it, the implementation might not be as trivial as they think. :)

#12 kyoryu   Members   -  Reputation: 224

Like
0Likes
Like

Posted 13 April 2009 - 02:40 PM

Quote:
Original post by raydey
Hey guys,

Just a quick question. I'm making a very basic program in c++ to calculate the time it takes to process a number of commands. I purposely want to push the processor as far as I can, so I was wondering whether anyone could suggest some CPU intensive operations. I already know about square root being relatively expensive, but was just wondering whether there were any others that were reasonably simple to code.

Cheers

Ray

EDIT: Sorry, I should say, I realise graphics rendering is expensive, but it's not really what I want to code. It's a very basic command line program, for quite a pointless experiment lol


Anything's espensive if you do it enough times.

#13 Cornstalks   Crossbones+   -  Reputation: 6995

Like
0Likes
Like

Posted 13 April 2009 - 05:16 PM

Fractals. Or, more specifically, the Mandelbrot Set.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#14 iMalc   Crossbones+   -  Reputation: 2306

Like
0Likes
Like

Posted 13 April 2009 - 08:03 PM

Quote:
Original post by alvaro
Quote:
Original post by ibebrett
factor a large prime.


Factoring primes is a trivial process. I can do it by hand very very quickly. :)
Yeah. Factoring suspected primes on the other hand...
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

#15 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 13 April 2009 - 08:37 PM

If this is for university, then a Whitted style Ray Tracer should be basic enough; but also non-trivial enough w.r.t. codepaths and codelength (of the binary) that the compiler and the CPU won't have a too easy job.

In terms of lines of code (...), I can assure it is not too complex. Look what I said in another recent thread:

Quote:
Original post by phresnel
edit: Oh, and of course, to produce a 4k demo, you won't need a millions lines of code ;), in fact, awesome results can be produced in less then 100 lines of code (see Kevin Beason's 100pt: SmallPT: Global Illumination in 99 Lines of C or tbp's sphereflake-in-a-hundred-lines renderer.

(see also the thread on ompf; what I want to say: if you can write a path tracer in 99 LoC, you will even more be able to write a whitted style one in less than 100 LoC)

To unmaterialize that you are not interested in graphics programming: Well, that thing doesn't need more graphical output then dumping to stdout as a ppm file (see linked thread on ompf again).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS