Juan Ribes Vidal wrote:
>
> Hi!
>
> I have to write some JavaScript code and I'm trying to find any object or
> function to know CPU-speed of the user. Is it possible? If it's not, żhow
> can I simulate it?
>
> Thank you very much.
--
Martin Honnen
http://javascript.faqts.com/
http://home.t-online.de/home/martin.honnen/jsgoddies.html
There are no browser or Javascript objects, which will tell you the
CPU-speed of the user.
Your only option is to emulate it, by doing a test. One way of doing this
would be to make a for loop and calculate the time it took, and repeat this
enough times untill you get a good average. This average should then form
the basis of a division, which you then multiply with an appropriate browser
and system offset.
I made a small function to do this, which currently only works on the
Windows platform with either IE 4/5 or Netscape 4+.
To broaden the use of this function, you would need to get the correct
offset values for each browser version (IE,NS,Opera,etc,etc..) on each
system (Win,Unix,Linux,Sun,etc,etc..), put these into a lookup table and get
the correct value for the offset from this lookup table depending on browser
and system, and put into the calculation.
function test_cpu(force){
var d=doc;dc=d.cookie,dcr=/CpuSpeed=([^;]+);/,r=dcr.exec(dc)
if (r&&!force){
mhz = r[1]
} else {
var average,t1,t2,t,l,report=0,passes,offset=d.all?110:150
passes = 40
for (l=0;l<passes;l++){
t1 = new Date().getTime()
for (t=0;t<20000;t++){}
t2 = new Date().getTime()
report += t2-t1
}
average = report/passes
mhz = parseInt((65/average)*offset)
d.cookie = 'CpuSpeed=' + mhz + ';'
}
return mhz
}
To ensure the user is only disturbed by this calculation once, the result is
stored in a cookie for future use. The function returns the visitors
CPU-speed in MHZ.
A higher number of passes takes more time, but gives a more precise average.
A lower number of passes takes less time, but gives a not so precise
average.
The only offsets in the function are for IE and NS 4 or higher on the
Windows platform.
--
Thor Larholm
Another exaple: one user has a new, just formated PC and runs only the
browser, the other has 7 programs running including heavy ones! Will
performance be the same ?
So the only thing you can actually measure this way is the overall
performance of his machine at this specific time. There is no way to
translate this into CPU speed.
Finally, to show how difficult is this task I have to say that (to my
knowledge) is impossible even by using the Windows API to find the CPU
speed. You may have noticed thatin the system dialog in control panel
it writes just the type of processor not his speed. I think I read
somewhere that the only way to achive that is to use a DLL design my
Intel or something like that. But all these have nothing to do with
javascript, I just want to show the size of the problem
Kostas Hatzikokolakis
On Thu, 15 Jun 2000 09:49:05 +0200, "Thor Larholm" <th...@jubii.dk>
wrote:
>"Juan Ribes Vidal" <jri...@siconet.es> wrote in message
>news:mJK15.121$5vq2.1...@news.jazztel.es...
>> Hi!
>>
>> I have to write some JavaScript code and I'm trying to find any object or
>> function to know CPU-speed of the user. Is it possible? If it's not, ?how
I agree completely.
> Another exaple: one user has a new, just formated PC and runs only the
> browser, the other has 7 programs running including heavy ones! Will
> performance be the same ?
Certainly not.
> So the only thing you can actually measure this way is the overall
> performance of his machine at this specific time. There is no way to
> translate this into CPU speed.
Exactly my words, I just forgot to include them in my previous post.
> Finally, to show how difficult is this task I have to say that (to my
> knowledge) is impossible even by using the Windows API to find the CPU
> speed. You may have noticed thatin the system dialog in control panel
> it writes just the type of processor not his speed. I think I read
> somewhere that the only way to achive that is to use a DLL design my
> Intel or something like that. But all these have nothing to do with
> javascript, I just want to show the size of the problem
Well, you can always make an ActiveX component, if you are running a
Windows/IE only environment. Since any ActiveX has complete access to the
computer, it can read the CPU-speed directly from your BIOS, and get a 100%
match.
--
Thor Larholm
I'm saving this one for later.
--Seth
Thor Larholm wrote in part: