Thread in_array() - Funktion bauen (25 answers)
Opened by Gast at 2005-10-13 15:58

Cremator
 2005-10-13 23:10
#58782 #58782
User since
2003-11-26
97 Artikel
BenutzerIn
[default_avatar]
[quote=pq,13.10.2005, 14:30][quote=phaylon,13.10.2005, 13:10]perldoc -f grep[/quote]
grep ist aber ineffizient.[/quote]
Aehm.. mein Perl sagt was anderes.

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
use Benchmark;
use strict;
use List::Util qw(first);
my @x = (0..50000);
Benchmark::cmpthese(1000000, {
'Grep' => 'my $y = grep {$_ == 45000} @x',
'Util' => 'my $y = first {$_ == 45000} @x' });

# Ergibt
Rate Util Grep
Util 914077/s -- -63%
Grep 2463054/s 169% --


Abgesehen davon finde ich die Syntax mit first nicht besonders intuitiv.

View full thread in_array() - Funktion bauen