Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10627 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-06-25 08:03 +0000 |
| Last post | 2012-06-25 08:03 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Replace, ReplaceAll and If time performace comparition Bob Hanlon <hanlonr357@gmail.com> - 2012-06-25 08:03 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-06-25 08:03 +0000 |
| Subject | Re: Replace, ReplaceAll and If time performace comparition |
| Message-ID | <js960p$f3p$1@smc.vnet.net> |
With a pattern you get a slight improvement with
(randomList /. (_?Negative -> 0))
However, Clip is much faster
Clip[randomList, {0, Infinity}]
Bob Hanlon
On Sun, Jun 24, 2012 at 4:26 AM, Murta <rodrigomurtax@gmail.com> wrote:
> 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
>
--
Bob Hanlon
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web