Parameter
You can also set the maximum thread count in ColdFusion Administrator. Click Server Settings > Settings and specify the number of threads in Default Maximum Thread Count For Parallel Functions.
Description
Iterates over every entry of the array and calls the closure function to work on the element of the array. The returned value will be set at the same index in a new array and the new array will be returned
Array
Syntax
arrayMap(array, function(item [,index, array]){} [, parallel] [, maxThreadCount]) |
ColdFusion (2021 release): Introduced the following parameters:
ColdFusion (2018 release): Introduced named parameters.
ColdFusion 11: Added this function.
|
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. |
ColdFusion community blog on Map, reduce, and filter functions.
<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>
Sign in to your account