Question: 5) Look at the below code. It takes 7 seconds

This question is related to the Question Task/Threads simultaneous download

5) Look at the below code. It takes 7 seconds to make the call to yahoo finance 4 times
sequentially. The strange thing is that it takes the same amount of seconds to do the call
in parrallel....hummm very strange....what is the benefit of using the Task command then ??
I have 4 cores in my machine ie kernelopts(numcpus) returns 4 so it should be very fast.


restart:
with(Sockets):


X1 := proc () local str, sid, b; global str1;
str := "";
sid := Open("google.com", 80);
Write(sid, cat("GET /finance/historical?q=INDEXSP:.INX&histperiod=daily HTTP/1.0 \n\n"));
b := Read(sid);
while b <> false do str := cat(str, b); b := Read(sid) end do;
Close(sid);
str
end proc;


X2 := proc () local str, sid, b; global str1;
str := "";
sid := Open("google.com", 80);
Write(sid, cat("GET /finance/historical?q=INDEXEURO:.FCHI&histperiod=daily HTTP/1.0 \n\n"));
b := Read(sid);
while b <> false do str := cat(str, b); b := Read(sid) end do;
Close(sid);
str
end proc;


st := time[real]();

X1(); X2(); X1(); X2();

"Sequentially" = time[real]()-st;


st := time[real]();
Threads:-Task:-Start(X1);
Threads:-Task:-Start(X2);
Threads:-Task:-Start(X1);
Threads:-Task:-Start(X2);

"Simultaneously" = time[real]()-st;



                     "Sequentially" = 7.735
                        "Simultaneously" = 7.094

This has been branched into the following page(s):
Please Wait...