summaryrefslogtreecommitdiffstats
path: root/bm
diff options
context:
space:
mode:
Diffstat (limited to 'bm')
-rw-r--r--bm/bm_size.pl90
1 files changed, 90 insertions, 0 deletions
diff --git a/bm/bm_size.pl b/bm/bm_size.pl
new file mode 100644
index 0000000..af8c8e7
--- /dev/null
+++ b/bm/bm_size.pl
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use File::Spec;
+use File::Path qw(remove_tree);
+use Cwd qw(getcwd abs_path);
+
+my ($files, $depth) = @ARGV;
+if (!defined $files || !defined $depth) {
+ die "Usage: perl bench.pl <files> <depth>\n";
+}
+
+my $base_dir = getcwd();
+my $urn_bin = abs_path(File::Spec->catfile("..", "urn"));
+my $seed_bin = abs_path("seed.pl");
+my $bm_repo = "bm_repo";
+
+# Storage for results: $results{Action}{Tool} = "metrics string"
+my %results;
+my @actions = qw(Status Add Commit);
+
+sub run_benchmark {
+ my ($tool_name) = @_;
+
+ print "Running $tool_name...\n";
+
+ # 1. Seed
+ system("perl $seed_bin $files $depth > /dev/null 2>&1") == 0 or die "Seeding failed";
+ chdir($bm_repo) or die "Could not enter $bm_repo: $!";
+
+ # 2. Init
+ my $init_cmd = ($tool_name eq "URN") ? "perl $urn_bin init" : "git init";
+ system("$init_cmd > /dev/null 2>&1");
+
+ # 3. Timed Actions
+ my %cmds = (
+ "Status" => ($tool_name eq "URN") ? "perl $urn_bin status" : "git status",
+ "Add" => ($tool_name eq "URN") ? "perl $urn_bin add ." : "git add .",
+ "Commit" => ($tool_name eq "URN") ? "perl $urn_bin commit -m 'bench'" : "git commit -m 'bench'",
+ );
+
+ foreach my $action (@actions) {
+ my $cmd = $cmds{$action};
+ # Extract just real time and max rss for the table
+ my $raw = `(/usr/bin/time -l $cmd > /dev/null) 2>&1`;
+
+ # Parse specific metrics: Real time and Max RSS
+ my ($real) = $raw =~ /(\d+\.\d+)\s+real/;
+ my ($rss) = $raw =~ /(\d+)\s+maximum resident set size/;
+
+ $results{$action}{$tool_name} = {
+ time => $real // "N/A",
+ mem => $rss ? sprintf("%.2f MB", $rss / 1024 / 1024) : "N/A"
+ };
+ }
+
+ chdir($base_dir) or die $!;
+ remove_tree($bm_repo) if -d $bm_repo;
+}
+
+# Run the sequence
+run_benchmark("URN");
+run_benchmark("GIT");
+
+# --- Generate the report ---
+my $out_file = "BM_COMPARE_${files}_${depth}.txt";
+open(my $res, '>', $out_file) or die $!;
+
+my $header = sprintf("%-12s | %-18s | %-18s", "ACTION", "URN (Time/Mem)", "GIT (Time/Mem)");
+my $sep = "-" x length($header);
+
+print $res "BENCHMARK: $files files, $depth depth\n";
+print $res "$sep\n$header\n$sep\n";
+
+foreach my $action (@actions) {
+ my $u = $results{$action}{"URN"};
+ my $g = $results{$action}{"GIT"};
+
+ printf $res "%-12s | %6ss / %-8s | %6ss / %-8s\n",
+ $action,
+ $u->{time}, $u->{mem},
+ $g->{time}, $g->{mem};
+}
+
+print $res "$sep\n";
+close($res);
+
+print "\nComparison complete! Results saved to $out_file\n";
+system("cat $out_file");
+