Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

CPU Speed from Javascript

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
davidlars99
Asked:
davidlars99
  • 7
  • 5
2 Solutions
 
davidlars99Author Commented:
does anybody know what is the frame rate per second for regular home TV?
0
 
knightEknightCommented:
23 frame / sec
0
 
davidlars99Author Commented:
knightEknight, can you please tell me speed of your cpu...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
davidlars99Author Commented:
you have 1.8 or 1.5 right... I maybe wrong
0
 
knightEknightCommented:
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
 
knightEknightCommented:
but it is 1.8
0
 
davidlars99Author Commented:
ok then message box should say about 23-25... again I maybe wrond :-)
0
 
knightEknightCommented:
on my pc the message box said 35 / 25
0
 
knightEknightCommented:
but the moving box did not appear 100% smooth
0
 
davidlars99Author Commented:
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
 
PeterCNCommented:
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
 
davidlars99Author Commented:
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
 
davidlars99Author Commented:

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now