Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

r35448@mtl (orig r383): glasser | 2006-11-03 10:30:43 +0800

 Add a (failing) performance test.  (Current value: ~2.8.)
 


git-svn-id: svn://svn.bestpractical.com/Data-Hierarchy@15812 e417ac7c-1bcc-0310-8ffa-8f5827389a85
  • Loading branch information...
commit a61e43d34c964a9375d13b5630f03c26f06aadad 1 parent 6c78ead
authored September 08, 2008

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  trunk/t/7performance.t
41  trunk/t/7performance.t
... ...
@@ -0,0 +1,41 @@
  1
+#!/usr/bin/env perl
  2
+
  3
+use Test::More tests => 2;
  4
+use Benchmark;
  5
+
  6
+BEGIN {
  7
+    use_ok 'Data::Hierarchy';
  8
+}
  9
+
  10
+use constant ITERATIONS => 2;
  11
+use constant MULTIPLIER => 3;
  12
+use constant N => 200;
  13
+
  14
+# Returns the power of n that $code grows by.
  15
+sub order_of_growth {
  16
+    my $n = shift;
  17
+    my $code = shift;
  18
+
  19
+    my $time_small = timeit(ITERATIONS, sub { $code->($n) });
  20
+    my $time_large = timeit(ITERATIONS, sub { $code->($n * MULTIPLIER) });
  21
+
  22
+    # use 'user' time
  23
+    my $ratio = $time_large->[1]/$time_small->[0];
  24
+
  25
+    return log($ratio)/log(MULTIPLIER);
  26
+}
  27
+
  28
+my $growth = order_of_growth(N, sub {
  29
+                                 my $n = shift;
  30
+                                 diag "doing $n";
  31
+                                 
  32
+                                 my $d = Data::Hierarchy->new;
  33
+                                 my $kv = { foo => 'bar' };
  34
+                                 while ($n > 0) {
  35
+                                     $n--;
  36
+                                     $d->store("/A/$n", $kv);
  37
+                                 }
  38
+                                 $d->store("/A", $kv);
  39
+                             });
  40
+
  41
+is ($growth < 1.5, "Data::Hierarchy scales poorly: $growth");

0 notes on commit a61e43d

Please sign in to comment.
Something went wrong with that request. Please try again.