Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10619 > unrolled thread

Replace, ReplaceAll and If time performace comparition

Started byMurta <rodrigomurtax@gmail.com>
First post2012-06-24 08:24 +0000
Last post2012-06-24 08:24 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Replace, ReplaceAll and If time performace comparition Murta <rodrigomurtax@gmail.com> - 2012-06-24 08:24 +0000

#10619 — Replace, ReplaceAll and If time performace comparition

FromMurta <rodrigomurtax@gmail.com>
Date2012-06-24 08:24 +0000
SubjectReplace, ReplaceAll and If time performace comparition
Message-ID<js6isk$85n$1@smc.vnet.net>
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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web