在Perl搜索中,用大型变量取代,需要很长时间。
例如。
$original = aaaabc ;
$replace = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb x 1000
$original =~ s/b/$replace/;
一旦<代码> 替换代码>的大小便足够大,该编码可占用很长时间。 我假定一些缓冲被破坏,并不断延伸。
是否有改进业绩的建议?
在Perl搜索中,用大型变量取代,需要很长时间。
例如。
$original = aaaabc ;
$replace = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb x 1000
$original =~ s/b/$replace/;
一旦<代码> 替换代码>的大小便足够大,该编码可占用很长时间。 我假定一些缓冲被破坏,并不断延伸。
是否有改进业绩的建议?
规模如何大? 替换是在我的视窗盒上的第二座,即使有一段长度30 000 00030 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000美元:
> perl -Mstrict -wE "my $start = time;my $str = aaaabc ; my $replace = b x 30_000_000_000_000_000_000; $str =~ s/b/$replace/; printf qq<%d s
>, time - $start;"
0 s
不清楚为什么你看到业绩恶化。 我为取代500+特性做了扼杀,然后以书面方式执行你的方案。
$ time(perl large.pl )
real 0m0.010s
user 0m0.002s
sys 0m0.004s
$
然而,我确实有建议。 如果你更换舱位的长度与你相同,那么为什么在你最初的舱位中找不到特殊性,将照样照相,把部件放在更换的前线和背面,并打印?
Benchmark gives 0 wallclock secs with your input
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $original = aaaabcd ;
my $replace = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb x 1000;
my $start_time = new Benchmark;
$original =~ s/b/$replace/;
my $end_time = new Benchmark;
my $diff = timediff($end_time,$start_time);
print "Regex took:",timestr($diff);
产出
Regex took 0 wallclock secs (0.00 usr + 0.00 sys = 0.00 CPU)
I am building a Web interface to monitor an embedded system. I have built a Perl script which runs remote commands and gathers output from that system. Now what I need is a Web interface which makes ...
How do I tell what type of value is in a Perl variable? $x might be a scalar, a ref to an array or a ref to a hash (or maybe other things).
When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...
I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...
I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...
I would like to submit a form to a CGI script localy (w3c-markup-validator), but it is too slow using curl and apache, I want to use this CGI script more than 5,000 times in an another script. and ...
So I m running perl 5.10 on a core 2 duo macbook pro compiled with threading support: usethreads=define, useithreads=define. I ve got a simple script to read 4 gzipped files containing aroud 750000 ...
A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...