CPU core estimation with JavaScript
blog.wg.oftn.org
blog.wg.oftn.org
(1) Intel Turbo Boost, which will run a single core at higher frequency than multiple cores (to make matters worse, this is also dependent on the CPU's temperature).
(2) Hyperthreading giving you anywhere between a x2 and no speedup depending on what your code is doing under the hood.
(3) NUMA giving, well, non-uniform speedups for some memory access patterns.
(4) Background processes occupying 1+ cores.
* Linux Mint 14 (x64): 6 cores
* Arch Linux (x64) machine #1: 6 cores
* Arch Linux (x64) machine #2: 14 cores
And on a HP desktop, also dual core i5: * Windows 7 (x64) on Firefox: 3 cores
* Windows 7 (x64) on IE: no result at all, demo hangs
Back to the drawing board I'm afraid...Chrome 27: 1 or 2 cores. Chrome 26 gave me 3 a few times.
Firefox 21: 8-16 cores. One times out of four, the test goes up to testing 32 cores, but the CPU activity drops abruptly, and the test hangs (the button text remains a greyed out "Running").
Safari 6.04: 1 core. Rarely two.
But why even try to estimate the number of cores? Just call it a benchmark that tries to find the number of threads you should run.
And you're right, we designed the script to find the optimum number of web workers to use in parallel, that's what it's primary purpose is. But we also want to drive adoption of navigator.cores so we decided to call it a core estimator.
Also, I thought browsers didn't offer more thread access...
(1): Opera 12.15, Debian GNU/Linux, Intel(R) Core(TM)2 Duo CPU U9600 @ 1.60GHz.
Edit: worked quite well on my nexus 4. Got 4 cores on the first test.
If the goal is to find the sweat spot for an algorithm, wouldn't it be best to ran several small tests of the specific algorithm with different optimization values?
As other people have pointed out, things like Intel speed boost change the performance characteristics of the machine, and things like virtualization can flat-out lie about the capacity of the machine.
It seems like a far more preferable solution is to lightly parallelize based on generic defaults and let the OS handle switching, instead of trying to outsmart the system.
IE10: consistently 7 cores, 11.0 seconds; FF21: consistently 4 cores, unconsistently 15—17 seconds; Cr27: consistently 4 cores, 16.0 seconds.
And secondly, the demo said my old T7300 dual core would have 3 core.
Web workers make it possible to do parallel computation with JavaScript, and knowing the right number to spawn helps to make sure resources are being taken advantage of. We already have the ability to run JavaScript code on multiple processors, but currently, you can't tell where it's being run. For performance reasons, knowing the number of workers to spawn can make a big difference.
Secondly, it's called an estimator so it's never going to be perfect. It's a tool designed to give you some idea of what is going on.
If you want to push for something, push for a mechanism that frees you from having to set the number of workers to spawn.
> In a compute-bound application running on an N-processor machine, adding additional threads may improve throughput as the number of threads approaches N, but adding additional threads beyond N will do no good. Indeed, too many threads will even degrade performance because of the additional context switching overhead. The optimum size of a thread pool depends on the number of processors available and the nature of the tasks on the work queue. On an N-processor system for a work queue that will hold entirely compute-bound tasks, you will generally achieve maximum CPU utilization with a thread pool of N or N+1 threads.
From http://www.ibm.com/developerworks/library/j-jtp0730/index.ht...
As I see from others, the result reported by core-estimator is spot on N+1, where N is the number of virtual cores [2].
It might be a coincidence, but this is exactly the number of jobs one would give to make when compiling [3].
Knowing N helps to be efficient when spawning threads (avoiding swamping or starving cores).
[1] http://ark.intel.com/products/52229/ [2] as reported for example by /proc/cpuinfo on Linux [3] i.e. "make -j5"
Hoping (P)NaCl will pick up steam soon...
Made me smile a bit.
Then I ran it a second time, got up to 32 cores, and the app crashed my browser.
I have two cores.
i5-2500k 4cores - 4 threads.