Whatever message this page gives is out now! Go check it out!
arrayMap(array, function(item [,index, array]){} [, parallel] [, maxThreadCount]) |
Parameter | Req/Opt | Description |
array | Req | The input array. |
callback | Req | Closure or a function reference that will be called for each iteration. The arguments passed to the callback are:
|
maxThreadCount | Opt | The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
parallel | Opt | True if you want to enable parallel programming. |
<cfscript>
myArray=ArrayNew(1);
myArray = [ 1,5,7,9,11 ];
newArray = arrayMap(myArray, function(item){
return item;
});
writeDump(newArray);
</cfscript><cfscript>
for(i=1;i<=100001;i++){
arr[i]=i
}
//writeDump(arr)
callback=function(item){
return sqr(item)
}
// without parallelization
t_start=GetTickCount()
newArray=arrayMap(arr,callback)
t_end=GetTickCount()
writeOutput("Time taken without parallelization: " & t_end-t_start)
writeOutput("<br/>")
// with parallelization
t_start=GetTickCount()
pArray=arrayMap(arr,callback,true,10)
t_end=GetTickCount()
writeOutput("Time taken with 10 threads: " & t_end-t_start)
writeOutput("<br/>")
// with parallelization
t_start=GetTickCount()
pArray=arrayMap(arr,callback,true,20)
t_end=GetTickCount()
writeOutput("Time taken with 20 threads: " & t_end-t_start)
writeOutput("<br/>")
// with parallelization
t_start=GetTickCount()
pArray=arrayMap(arr,callback,true,30)
t_end=GetTickCount()
writeOutput("Time taken with 30 threads: " & t_end-t_start)
writeOutput("<br/>")
// with parallelization
t_start=GetTickCount()
pArray=arrayMap(arr,callback,true,40)
t_end=GetTickCount()
writeOutput("Time taken with 40 threads: " & t_end-t_start)
writeOutput("<br/>")
</cfscript>