Skip to main content
Commonmark migration
Source Link

EDIT

As Szabolcs has pointed out in his post, auto-compilation in Map is in fact not the cause of the issue in OP. For context I will leave my original post.

ORIGINAL POST

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

 

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

EDIT

As Szabolcs has pointed out in his post, auto-compilation in Map is in fact not the cause of the issue in OP. For context I will leave my original post.

ORIGINAL POST

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

 

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

EDIT

As Szabolcs has pointed out in his post, auto-compilation in Map is in fact not the cause of the issue in OP. For context I will leave my original post.

ORIGINAL POST

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

added 191 characters in body
Source Link

EDIT

As Szabolcs has pointed out in his post, auto-compilation in Map is in fact not the cause of the issue in OP. For context I will leave my original post.

ORIGINAL POST

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

EDIT

As Szabolcs has pointed out in his post, auto-compilation in Map is in fact not the cause of the issue in OP. For context I will leave my original post.

ORIGINAL POST

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.

Source Link

In your example, this happens because Map can auto-compile certain functions, and N@Sin[#] & fits the auto-compilation criteria. You can read a very good post about it here, by Leonid Shifrin. The fact that autocompilation is the "culprit" here can be verified by turning it off and checking the timing again:

System`SetSystemOptions["CompileOptions" -> "MapCompileLength" -> Infinity];
Map[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First
ParallelMap[(N@Sin[#]) &, Range[10000000]] // AbsoluteTiming // First

gives

13.477214

2.432819

on my machine. So, the parallel version is now faster.

I'm not sure that you are aware of this, but (at least in my experience) using Listable functions and so-called vectorized operations can have much larger potentials for speed-up than using parallelization. Here we would do

Sin@N@Range[10000000] // AbsoluteTiming // First

0.100697

i.e. no need for Map at all.