in reply to RE: RE: From one beginner to others . . .
in thread From one beginner to others . . .
Note the whopping improvement in performance of Split3. In my benchmark, it's approximately twice as fast as the regex.#!/usr/bin/perl -w use strict; use Benchmark; use vars qw($myvar $result $a $b $c $d); $myvar = "one,two,three,four"; timethese(1000000, { Regex => '$a=$1, $b=$2, $c=$3, $d=$4 if $myvar =~ /^[^,]+,([^,] ++),[^,]+,[^,]+$/', Split1 => '$result = (split /,/, $myvar)[1]', Split2 => '$result = (split /,/, $myvar, 4)[1]', Split3 => '$result = (split /,/, $myvar, 3)[1]' }); Benchmark: timing 1000000 iterations of Regex, Split1, Split2, Split3. +.. Regex: 26 wallclock secs (25.75 usr + 0.00 sys = 25.75 CPU) Split1: 16 wallclock secs (16.31 usr + 0.00 sys = 16.31 CPU) Split2: 16 wallclock secs (16.15 usr + 0.00 sys = 16.15 CPU) Split3: 13 wallclock secs (12.74 usr + 0.00 sys = 12.74 CPU)
Cheers,
Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: RE: From one beginner to others . . .
by Abigail (Deacon) on Jul 16, 2000 at 01:08 UTC | |
by Ovid (Cardinal) on Jul 16, 2000 at 04:08 UTC |