Skip to main content
Tweeted twitter.com/#!/StackMma/status/610965735062507521
deleted 31 characters in body
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Can anyone help explain why MapThread is so slow in this simple case?

p = 0.1;
t = Table[1, {10^6}];
SeedRandom[1000];
AbsoluteTiming[
AbsoluteTiming[a a=Map[#= Map[# RandomChoice[{p, 1 - p} -> {1, 0}] &,t];
 ]t];]
SeedRandom[1000];
AbsoluteTiming[
AbsoluteTiming[b b=MapThread[#= MapThread[# RandomChoice[{p, 1 - p} -> {1, 0}] &,
   {t}];
 ]];]
Norm[a-b]

outputs

{0.555723, Null}
{3.696282, Null}
0

Can anyone help explain why MapThread is so slow in this simple case?

p = 0.1;
t = Table[1, {10^6}];
SeedRandom[1000];
AbsoluteTiming[
 a=Map[# RandomChoice[{p, 1 - p} -> {1, 0}] &,t];
 ]
SeedRandom[1000];
AbsoluteTiming[
 b=MapThread[# RandomChoice[{p, 1 - p} -> {1, 0}] &,
   {t}];
 ]
Norm[a-b]

outputs

{0.555723, Null}
{3.696282, Null}
0

Can anyone help explain why MapThread is so slow in this simple case?

p = 0.1;
t = Table[1, {10^6}];
SeedRandom[1000];
AbsoluteTiming[a = Map[# RandomChoice[{p, 1 - p} -> {1, 0}] &, t];]
SeedRandom[1000];
AbsoluteTiming[b = MapThread[# RandomChoice[{p, 1 - p} -> {1, 0}] &, {t}];]
Norm[a-b]

outputs

{0.555723, Null}
{3.696282, Null}
0
Source Link
user30193
user30193

Speed and the MapThread function

Can anyone help explain why MapThread is so slow in this simple case?

p = 0.1;
t = Table[1, {10^6}];
SeedRandom[1000];
AbsoluteTiming[
 a=Map[# RandomChoice[{p, 1 - p} -> {1, 0}] &,t];
 ]
SeedRandom[1000];
AbsoluteTiming[
 b=MapThread[# RandomChoice[{p, 1 - p} -> {1, 0}] &,
   {t}];
 ]
Norm[a-b]

outputs

{0.555723, Null}
{3.696282, Null}
0