summaryrefslogtreecommitdiff
path: root/plain.pl
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-05-14 18:37:14 +0200
committerYorhel <git@yorhel.nl>2019-05-14 18:38:12 +0200
commit04719fb0dd62858f97996f791a2318e062b90544 (patch)
tree47f820a61ab0ee7757740e8cd6367f31e1e310ed /plain.pl
Initial commit
Diffstat (limited to 'plain.pl')
-rwxr-xr-xplain.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/plain.pl b/plain.pl
new file mode 100755
index 0000000..4bc30f5
--- /dev/null
+++ b/plain.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# Usage: ./plain.pl db-plain db-gzip
+
+use strict;
+use warnings;
+use PerlIO::gzip;
+use v5.10;
+
+sub lookup_str {
+ my($F, $q) = @_;
+ while(<$F>) {
+ chomp;
+ return 1 if $q eq $_;
+ return 0 if $q lt $_;
+ }
+ return 0;
+}
+
+sub lookup_plain {
+ my($q, $f) = @_;
+ open my $F, '<', $f or die $!;
+ lookup_str $F, $q
+}
+
+sub lookup_gzip {
+ my($q, $f) = @_;
+ open my $F, '<:gzip', $f or die $!;
+ lookup_str $F, $q
+}
+
+my($plain, $gzip) = @ARGV;
+
+use Benchmark 'timethis', ':hireswallclock';
+sub rstr { state $s=['a'..'z','A'..'Z','0'..'9','!','@','#']; join '', map $s->[rand @$s], 1..5 }
+srand 0;
+timethis 2, sub { lookup_plain rstr(), $plain }, 'plain';
+srand 0;
+timethis 2, sub { lookup_gzip rstr(), $gzip }, 'gzip';