• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
raydey

Computationally Expensive Operations

14 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by ibebrett
factor a large prime.


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

0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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. :)
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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...
0

Share this post


Link to post
Share on other sites
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).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0