MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Replace, ReplaceAll and If time performace comparition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127019] Replace, ReplaceAll and If time performace comparition
  • From: Murta <rodrigomurtax at gmail.com>
  • Date: Sun, 24 Jun 2012 04:26:08 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

HI all
I was working in some simulations with random numbers and get this example of performance comparition.

randomList = RandomInteger[{-100, 100}, 10 10^6];

(randomList /. (x_ /; x < 0 -> 0)); // AbsoluteTiming
{5.747133, Null}

Replace[randomList, (x_ /; x < 0 -> 0), 1]; // AbsoluteTiming
{4.758984, Null}

(If[# < 0, 0, #] & /@ randomList); // AbsoluteTiming
{0.572200, Null}

I personally prefer work with patterns because they are more compact and functional.
Someone knows why patter is one magnitude order slow?? There is some trick to make it faster?

tks
Murta



  • Prev by Date: Re: plot legend with filling
  • Next by Date: Re: Integration anomaly?
  • Previous by thread: NDSolve and multi-cores
  • Next by thread: Re: Replace, ReplaceAll and If time performace comparition