1#!/usr/bin/env perl 2 3=head1 NAME 4 5turtle_benchmark.pl - Benchmark tool for Turtle parser 6 7=head1 USAGE 8 9 turtle_benchmark.pl FILE [LIMIT] 10 11Parses the input turtle FILE and prints the overall parsing speed. 12If LIMIT is specified, stops after LIMIT triples have been parsed. 13 14=cut 15 16use strict; 17use warnings; 18use RDF::Trine; 19use Time::HiRes qw(gettimeofday tv_interval); 20use RDF::Trine::Parser::Turtle; 21 22$| = 1; 23my $filename = shift; 24my $limit = shift || 0; 25open(my $fh, '<:encoding(UTF-8)', $filename) or die $!; 26my $count = 0; 27my $t0 = [gettimeofday]; 28my $p = RDF::Trine::Parser::Turtle->new(); 29eval { 30 $p->parse_file(undef, $fh, sub { 31 $count++; 32 print STDERR "\r$count" unless ($count % 7); 33 die if ($limit and $count >= $limit); 34 }); 35}; 36my $elapsed = tv_interval( $t0, [gettimeofday]); 37printf("\nParsed %d triples in %.1fs (%.1f T/s)\n", $count, $elapsed, ($count/$elapsed)); 38