java - What is the time complexity of Arrays.parallelSetAll()? -


i read : everything java 8 that, java 8 adds arrays.parallelsetall()

int[] array = new int[8]; atomicinteger i= new atomicinteger(); arrays.parallelsetall(array, operand -> i.incrementandget()); 

[edited] o(1) or constant time complexity on same machine same no.of elements in array ? sort of performance improvement indicated method name?

to start off, can never o(1), more clarification following:

i using n = array.length, in case 8, not matter big number.

now observe do:

for (int = 0; < n; i++) {     array[i] = i.incrementandget(); } 

this java 8 easier:

arrays.setall(array, v -> i.incrementandget()); 

observe both take o(n) time.

now take account execute code parallel, there no guarantees how executes it, not know number of parallellizations under hood, if @ such low number.

therefore still takes o(n) time, because cannot prove parallellize on n threads.

edit, extra, have observed seem think parallellizing action means o(k) converge o(1), k = n or k = n^2, etc.
not case in practice can prove never have k processor cores available.

an intuitive argument own computer, if lucky may have 8 cores, therefore maximum time under perfect parallellization conditions o(n / 8).
i can hear people future laughing @ had 8 cpu cores...


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -