Question: Executing a procedure with the Task module seems slower. What am I doing wrong?

I'm optimizing some code and I have noticed that running a procedure within the Threads:-Task module seems to slow the procedure down. I want to use Threads:-Task to run many procedures in parallel and so finish a task faster.
I'm attaching an example of a simple "add" procedure run outside the Task module and within the Task module. As far as I know, the procedure is thread-safe, and this is shown by the similar time it takes to run 1 or 10 simultaneously.
What is going wrong?

``

restart

addproc := proc () local i, A; A := 0; A := add(i, i = 1 .. 1000); return A end proc

ts := time[real](); for t to 1000 do addproc() end do; TA := time[real]()-ts

ts := time[real](); for t to 1000 do Threads:-Task:-Start(null, Task = addproc) end do; TS := time[real]()-ts

ts := time[real](); for t to 1000 do Threads:-Task:-Start(null, Tasks = [addproc, addproc, addproc, addproc, addproc, addproc, addproc, addproc, addproc, addproc]) end do; TM := time[real]()-ts

TA; TS; TM

0.33e-1

 

2.049

 

2.006

(1)

TM/TA

60.78787879

(2)

``


 

Download TaskExample.mw

Please Wait...