The output is:BEGIN { print time . "\n"; } use List::MoreUtils qw/any/; BEGIN { print time . "\n"; } print time . "\n"; my @a = any {$_== 92} 1..100000000; print "\n"; print time; print "\n"; print @a;
1325041203 1325041203 1325041218 1325041218 1
What is taking the 15 seconds here?
I guessed it was caused by initializing the array 1..100000000 ,and I tested it in C ,it's really less than 1 second:
Please pay close attention to the output given above(or you can try it yourself), seems no one has noticed the output ...int *array = malloc(100000000 * sizeof(int)); int i; for(i = 0; i < 100000000; i++){ array[i] = i + 1; }
I printed the time before and after the iteration, the result is both 1325041218:
print time . "\n"; my @a = any {$_== 92} 1..100000000; print "\n"; print time;
So the time is not taken by the iteration..
In reply to Why it takes so much time here? by PerlOnTheWay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |