chiark / gitweb /
chain.c: Use `short' for word and chain lengths, except for QP tries.
[wordchain] / format-data
1 #! /usr/bin/perl -w
2
3 use autodie;
4 use strict;
5
6 our %MAP =
7   ("c++-map"        => 'GNU \textsf{libstdc++} \textsf{std::map}',
8    "c++-uomap"      => 'GNU \textsf{libstdc++} \textsf{std::unordered\_map}',
9    "golang"         => 'Golang \textsf{map}',
10    "libavl-avl"     => 'GNU \textsf{libavl} plain AVL trees',
11    "libavl-pavl"    => 'GNU \textsf{libavl} AVL trees, parent pointers',
12    "libavl-rtavl"   => 'GNU \textsf{libavl} AVL trees, right threaded',
13    "libavl-tavl"    => 'GNU \textsf{libavl} AVL trees, threaded',
14    "libavl-rb"      => 'GNU \textsf{libavl} plain red-black trees',
15    "libavl-prb"    => 'GNU \textsf{libavl} red-black trees, parent pointers',
16    "libavl-rtrb"    => 'GNU \textsf{libavl} red-black trees, right threaded',
17    "libavl-trb"     => 'GNU \textsf{libavl} red-black trees, threaded',
18    "lisp-ccl"       => 'Common Lisp (Clozure CL)',
19    "lisp-clisp"     => 'Common Lisp (GNU CLisp)',
20    "lisp-cmucl"     => 'Common Lisp (CMU CL)',
21    "lisp-ecl"       => 'Common Lisp (ECL)',
22    "lisp-sbcl"      => 'Common Lisp (SBCL)',
23    "mLib-sym"       => 'mLib, \textsf{sym} hash table',
24    "perl"           => 'Perl hash',
25    "python"         => 'Python \textsf{dict}',
26    "qptrie-qp-fanf" => 'Four-bit QP-trie, recursive \textsf{Tnextl}',
27    "qptrie-qp-mdw"  => 'Four-bit QP-trie, iterative \textsf{Tnextl}',
28    "qptrie-qp-list" => 'Four-bit QP-trie, linked list',
29    "qptrie-fn-fanf" => 'Five-bit QP-trie, recursive \textsf{Tnextl}',
30    "qptrie-fn-mdw"  => 'Five-bit QP-trie, iterative \textsf{Tnextl}',
31    "qptrie-fn-list" => 'Five-bit QP-trie, linked list',
32    "rust-btree"     => 'Rust \textsf{std::collections::BTreeMap}',
33    "rust-hash"      => 'Rust \textsf{std::collections::HashMap}',
34    "sgt-tree234"    => "Simon Tatham's 2-3-4 tree",
35    "xyla-avl"       => 'Xyla AVL tree',
36    "xyla-rb"        => 'Xyla red-black tree',
37    "xyla-splay"     => 'Xyla splay tree',
38    "xyla-treap"     => 'Xyla treap');
39
40 our @STAT = ("lower whisker",
41              "lower quartile",
42              "median",
43              "average",
44              "upper quartile",
45              "upper whisker");
46
47 my @X;
48 while (<>) {
49   my ($impl, $data, $stat) = m{ ^ (\S+)
50                                  ((?: \s+ [0-9.]+)*) \s* \;
51                                  ((?: \s+ [0-9.]+){6}) \s* $ }x
52     or die "bad line";
53   my @data = map { $_ + 0.0 } split ' ', $data;
54   my @stat = map { $_ + 0.0 } split ' ', $stat;
55   my ($wlo, undef, undef, undef, undef, $whi) = @stat;
56   my @out = grep { $_ < $wlo || $_ > $whi } @data;
57   push @X, [$impl, \@stat, \@out];
58 }
59
60 print  "\\begin{axis}\n";
61 printf "    [ytick = {%s},\n", join(", ", 1 .. @X);
62 print  "     yticklabels =\n";
63 for (my $i = 0; $i < @X; $i++) {
64   my $x = $X[$i];
65   printf "       %s{%s}%s\n",
66     $i ? " " : "{",
67     "\\textsf{$x->[0]}",
68     $i == @X - 1 ? "}]" : ",";
69 }
70 for my $x (@X) {
71   print  "  \\addplot+\n";
72   print  "      [boxplot prepared =\n";
73   my ($impl, $stat, $out) = $x->@*;
74   STAT: for (my $j = 0; $j < @STAT; $j++) {
75     next STAT unless defined $stat->[$j];
76     printf "         %s%s = %.3f%s\n",
77       $j ? " " : "{",
78       $STAT[$j], $stat->[$j],
79       $j == @STAT - 1 ? "}]" : ",";
80   }
81   printf "    coordinates {%s};\n",
82     join(" ", map { sprintf "(0, %.3f)", $_ } $out->@*);
83 }
84 print "\\end{axis}\n";