Solved

CPU Speed from Javascript

Posted on 2004-08-30
13
245 Views
Last Modified: 2012-05-05
hi, this is the javascript test, on page load it calls a function named calibrate(callbackfunction, speed_to_test) how it work is, that let's say you put <body onload="calibrate('init()',35)"> number 35 is the amount of frames per second to animate stabily on all PCs I'd say over 300mhz, or maybe less. that's what I'm gonna find out and that's the reason I came here.

I tested it on my and my friend's PCs mine is 2.3Ghz and his is 500Mhz. The purpose behind this function is that I'm working on Javascript based Pool, this function should stabilize ball collision and moving around the table, so far it works fine, but I wanted to triple check it and I would like you to go to this url and tell me:
1) what is the speed of your PC.
2) what does message box says.
Please do so and I promise soon you will be able to play the game.

http://www.frozendev.com/temp/speedtest.html

almost forgot pool will be 2 player game over the net, which means you can play with me and I can play with you...
I will accept 5 different comments and points will be split equaly

thank you
 dave
0
Comment
Question by:davidlars99
  • 7
  • 5
13 Comments
 
LVL 13

Author Comment

by:davidlars99
ID: 11934882
does anybody know what is the frame rate per second for regular home TV?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11934931
23 frame / sec
0
 
LVL 13

Author Comment

by:davidlars99
ID: 11934994
knightEknight, can you please tell me speed of your cpu...
0
 
LVL 13

Author Comment

by:davidlars99
ID: 11935013
you have 1.8 or 1.5 right... I maybe wrong
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11935033
david, I apologize ... I didn't run your test, I skipped to your second question about TV and answered spontaneously from memory.  The speed of my cpu has nothing to do with my previous post.  :)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11935039
but it is 1.8
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Author Comment

by:davidlars99
ID: 11935086
ok then message box should say about 23-25... again I maybe wrond :-)
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 250 total points
ID: 11935137
on my pc the message box said 35 / 25
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11935143
but the moving box did not appear 100% smooth
0
 
LVL 13

Author Comment

by:davidlars99
ID: 11935242
yes you're right, but it's OK, it has nothing to do with the idea. it for calming down unpatient users :-)

thank you
0
 
LVL 4

Assisted Solution

by:PeterCN
PeterCN earned 250 total points
ID: 11935624
It said I'd need a 23ms timeout for 35fps.

If I may give you some advice :-) Collision (and any other math stuff in a game for that matter) is not really the heavy part. Rather it's the moving around the screen of elements that takes the most cpu time. That means that if you put calculations AND moving in the same for loop, the calculations will have to wait for the moving on the screen to take place before going to the next loop. Take the imaginary piece of code below:

for(var i=0; i<lotsOfUpdates; i++) {

   // this doesn't really take a lot of time
   calculateStuff(i);

   // but this does, and i++ happens only when it's done
   outputToScreen(i);

}

If you'd rewrite that to store calculated positions, and do the moving in a separate timeout or interval, the result would run smoother using less cpu time, and you could smoothly animate more elements,

// interval A
for(var i=0; i<lotsOfUpdates; i++) {
   calculateAndStoreStuff(i);
}

// interval B
for(var j=0; j<lotsOfUpdates; j++) {
   storedOutputToScreen(j);
}
0
 
LVL 13

Author Comment

by:davidlars99
ID: 11935751
ok, I understand what you're saying, but you are not quite correct here take a look what it takes to move balls...

Y[i]+=Math.sin(D[i]*Math.PI/180)*30;
X[i]+=Math.cos(D[i]*Math.PI/180)*30;

number 30 is the actual speed of a ball as it colides to a another ball or the wall you decrease the value
after all done you have to do a little optimization like corner and ball rebounds and it will be as smooth as it should.

check the URL in original question I added moving ball
0
 
LVL 13

Author Comment

by:davidlars99
ID: 11935894

what I'm doing is this...

for(i=0;i<balls.length;i++){
       check collision using Math.atan2(...) to get angles and using Math.sqrt(...) to check how close they are from each other
       if close enough then change direction of colided balls like balls[i].dir=....
}
     
this example takes more cpu time then moving all pool balls at the same time. balls stop, decrease their speed once they colided to someting, these hearts just keep going and going, but thanks for you good advice Peter...

http://www.frozendev.com/other/hearts.asp
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now