From 58f70660e29a98056cbe5e5ba00c6eb471097b49 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 19 Apr 2026 09:53:02 +0800 Subject: BM: seed script. --- .gitignore | 2 +- bm/seed.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 bm/seed.pl diff --git a/.gitignore b/.gitignore index 6257f3d..a2c442a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ cvn .cvn/ -test_env*/ sandbox*/ +**/bm_repo/ **/*.o **/*.out diff --git a/bm/seed.pl b/bm/seed.pl new file mode 100644 index 0000000..7649b64 --- /dev/null +++ b/bm/seed.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +use strict; +use warnings; +use File::Spec; +use File::Path qw(make_path); + +my ($total_files, $max_depth) = @ARGV; + +if (!defined $total_files || !defined $max_depth) { + die "Usage: perl seed.pl \nExample: perl seed.pl 200 20\n"; +} + +my $target_root = "bm_repo"; +my $files_created = 0; + +# Helper to generate random "code-like" text +sub generate_content { + my $size_kb = 5 + int(rand(21)); # 5-25 KB + my $bytes = $size_kb * 1024; + my $content = ""; + my @chars = ('a'..'z', 'A'..'Z', '0'..'9'); + + while (length($content) < $bytes) { + my $line_len = 20 + int(rand(60)); + $content .= "\t" if rand() > 0.5; # Random indentation + for (1..$line_len) { $content .= $chars[rand @chars]; } + $content .= (rand() > 0.7) ? " " : ""; # Random spaces + $content .= "\n"; + } + return $content; +} + +sub seed_tree { + my ($current_path, $depth, $files_left) = @_; + return if $files_left <= 0; + + # Determine how many files to put in THIS directory + # Heuristic: Spread them out, but ensure at least 1 if depth remains + my $files_here = ($depth == $max_depth) + ? $files_left + : int($files_left / ($max_depth - $depth + 1)) + int(rand(3)); + + $files_here = $files_left if $files_here > $files_left; + + make_path($current_path) unless -d $current_path; + + for (1..$files_here) { + my $filename = "file_" . sprintf("%04d", ++$files_created) . ".txt"; + my $full_path = File::Spec->catfile($current_path, $filename); + open(my $fh, '>', $full_path) or die $!; + print $fh generate_content(); + close($fh); + } + + # If we have depth and files remaining, go deeper + if ($depth < $max_depth && ($files_left - $files_here) > 0) { + my $next_dir = File::Spec->catdir($current_path, "depth_" . ($depth + 1)); + seed_tree($next_dir, $depth + 1, $files_left - $files_here); + } +} + +print "Seeding $total_files files across $max_depth levels...\n"; +seed_tree($target_root, 1, $total_files); +print "Done. Created $files_created files in '$target_root'.\n"; -- cgit v1.2.3