initial commit
[urisagit/Sort-Maker.git] / paper / sort_bench.pl
CommitLineData
7468c584 1#!/usr/local/bin/perl
2
3use Benchmark;
4
5@int_10 = rand_padded_ints( 10, 4, 8 ) ;
6@int_100 = rand_padded_ints( 100, 4, 8 ) ;
7
8print "@int_10\n" ;
9print "@int_100\n" ;
10
11
12#bench_sorts( 1 << 10, [qw(cmp)], [qw( int_10 int_100 )] ) ;
13
14bench_sorts( 1 << 10, [qw(cmp default)], [qw( int_100 )] ) ;
15
16exit( 0 ) ;
17
18sub 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 ;
26timethese ( $count, {
27 'null' => sub { null() },
28BENCH
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 ) },
36BENCH
37 }
38 }
39
40 $bench_text .= <<BENCH ;
41} ) ;
42BENCH
43
44 print $bench_text ;
45
46 eval $bench_text ;
47}
48
49
50
51sub null {} ;
52
53
54sub sort_null {
55
56 @_ ;
57}
58
59sub sort_default {
60
61 sort @_ ;
62}
63
64sub sort_cmp {
65
66 sort { $a cmp $b } @_ ;
67}
68
69sub sort_num {
70
71 sort { $a <=> $b } @_ ;
72}