Sign in to follow this  

[java] How Can You Determine CPU Speed (MHz) During Runtime?

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

That information might be too low level to get using java. According to the exchange here: Measure mobiles CPU, "CPU cycles and processor power are meaningless since Java doesn't run directly on the hardware.", "You can only measure java VM performance. Other things can't be measured from within java"


As an aside, I wonder if the shmoove in that exchange is the same shmoove that hangs out here?

Share this post


Link to post
Share on other sites
I don't know that much Java so ignore me if I'm wrong. :)

Can Java speak to libs/dlls? Can you use something written in C++ in Java? If you can you could create something in C++ that gets the speed and returns it to the java object.

Share this post


Link to post
Share on other sites
You can use libraries with java with Sytem.loadLibrary("<name>");
There's also JNI, so you can wrap a C++ method that does the trick with a JNI one, returning the information for the JVM.

Son Of Cain

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What for? That kind of information is totally useless for games. Well, actually its useless for any kind of application except diagnostic software.

Share this post


Link to post
Share on other sites
Well, it is complicated and has to to with me using passive rendering and getting problem when scrolling. Since the Repaint is handled in a different thread than my event thread, scrolling get too fast and I get strange side effects. I solved that problem by limiting the scroll speed but since someone could be sitting with 400 MHz and someone else with 3 GHz I would want to vary the scroll speed accordingly and then avoiding the low spec user not to get buggy crappy software.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why passive rendering? Its not usable for games.

And uhm... what you want is some throtteling code, which adjusts accordingly to the time spend per frame. The cpu speed wouldnt help much, since the bottleneck could be elsewhere (eg some slow integrated intel graphics chipset on a 2ghz machine is slower than some 500mhz machine with a geforce2 [well, for games anyways]).

For that you have basically two options the first one is using 1.5 nanoTime (or the hidden 1.4.2 hiperf timer) or the rather bad default timer. The former is accurate enough for being used directly and the other one (if you need 1.4 compatibility) needs some tricks. You can find some example code here:

System.nanoTime()
http://www.javagaming.org/forums/index.php?topic=7579.msg66862#msg66862

System.currentTimeMillis()
http://www.javagaming.org/forums/index.php?topic=11640.msg93602#msg93602

Share this post


Link to post
Share on other sites
As the above AP said, you want some proper speed throttling rather than any kind of guess-the-speed mumbo-jumbo. Also repaint() is fundamentally unpredictable when it comes to timing, a much better approach is BufferStrategy with active rendering.

It also sounds like you're trying to do game logic in the event thread, don't do that! Keep all your logic and drawing in your main thread and have the event thread set states or events into a queue for later processing by the main thread.

Share this post


Link to post
Share on other sites

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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