本帖最后由 523066680 于 2017-9-6 11:48 编辑
| | | | | | | | | use Time::HiRes qw/time/; | | | | my $time_a = time(); | | my $max = 10000000; | | my @array = ( 1 .. $max ); | | | | my $idx = $max; | | while ($idx > 0) | | { | | $rand = int(rand($idx)); | | print $array[$rand],"\n"; | | $array[$rand] = $array[$idx-1]; | | $idx--; | | } | | | | printf STDERR "Time used: %.3fs\n", time() - $time_a;COPY |
转眼6年过去了,我也没啥进步,做点修改,电脑CPU比以前好了,
>popup.pl >d:/test.txt
Time used: 7.533s
如果不是print重定向到文件,而是写入到新的数组
Time used: 4.154 |