I know I am doing the repetitive and useless summing again and again. What confuses me is that using the same algorithm, I mean
for my $i (99 .. 60000) { my $sum; map {$sum += $_->{foo_value}} @lines[$i - $n + 1 .. $i]; push @res, $sum; } in perl and for(int i =99; i <= 60000; i++) { int sum = 0; for(int j = i - n +1; j < i; j++) sum += lines[$j].foo_value; res[i] = sum; } in c, there is a huge difference in efficiency. the c program, even using the same stupid algorithm, the cost of time is acceptable. So I translated it to perl , and avoid the slow subscripting operations using map on sliced array, I suppose the perl program would be slower, but I don't predict such a huge difference, you don't even need a benchmark or profiling tool to notice the efficiency difference. This is what I am confused. Thanks for your patience!