Commit | Line | Data |
7468c584 |
1 | #!/usr/local/bin/perl |
2 | |
3 | use Benchmark; |
4 | |
5 | @int_10 = rand_padded_ints( 10, 4, 8 ) ; |
6 | @int_100 = rand_padded_ints( 100, 4, 8 ) ; |
7 | |
8 | print "@int_10\n" ; |
9 | print "@int_100\n" ; |
10 | |
11 | |
12 | #bench_sorts( 1 << 10, [qw(cmp)], [qw( int_10 int_100 )] ) ; |
13 | |
14 | bench_sorts( 1 << 10, [qw(cmp default)], [qw( int_100 )] ) ; |
15 | |
16 | exit( 0 ) ; |
17 | |
18 | sub bench_sorts { |
19 | |
20 | my( $count, $sorts_ref, $data_names_ref ) = @_ ; |
21 | |
22 | my( $sort, $data_name, $bench_text ) ; |
23 | |
24 | |
25 | $bench_text = <<BENCH ; |
26 | timethese ( $count, { |
27 | 'null' => sub { null() }, |
28 | BENCH |
29 | |
30 | foreach $sort ( 'null', @{$sorts_ref} ) { |
31 | |
32 | foreach $data_name ( @{$data_names_ref} ) { |
33 | |
34 | $bench_text .= <<BENCH ; |
35 | '$sort-$data_name' => sub { my( \@sorted ) = sort_$sort( \@$data_name ) }, |
36 | BENCH |
37 | } |
38 | } |
39 | |
40 | $bench_text .= <<BENCH ; |
41 | } ) ; |
42 | BENCH |
43 | |
44 | print $bench_text ; |
45 | |
46 | eval $bench_text ; |
47 | } |
48 | |
49 | |
50 | |
51 | sub null {} ; |
52 | |
53 | |
54 | sub sort_null { |
55 | |
56 | @_ ; |
57 | } |
58 | |
59 | sub sort_default { |
60 | |
61 | sort @_ ; |
62 | } |
63 | |
64 | sub sort_cmp { |
65 | |
66 | sort { $a cmp $b } @_ ; |
67 | } |
68 | |
69 | sub sort_num { |
70 | |
71 | sort { $a <=> $b } @_ ; |
72 | } |