Skip to content

Instantly share code, notes, and snippets.

@ikegami
Last active November 22, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikegami/edbda23247d71288099fb4f6cbd2a654 to your computer and use it in GitHub Desktop.
Save ikegami/edbda23247d71288099fb4f6cbd2a654 to your computer and use it in GitHub Desktop.
>new.dat  perl -e'print "newline 111\nnewline 222\n";'
>test.dat perl -e'
   my $s = "dla4\n.Ends\nshe\n.Ends\nres\n.Ends\n";
   my $n = 2**30 / length( $s );
   print $s for 1 .. $n;
'

zdim

$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat

real    0m0.530s
user    0m0.000s
sys     0m0.014s

$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat

real    0m0.528s
user    0m0.014s
sys     0m0.000s

$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat

real    0m0.505s
user    0m0.014s
sys     0m0.000s

TLP

$ \cp test.dat test_copy.dat && time perl tlp.pl test_copy.dat new.dat

real    2m41.277s
user    2m39.820s
sys     0m1.450s

$ \cp test.dat test_copy.dat && time perl tlp.pl test_copy.dat new.dat

real    2m38.551s
user    2m37.009s
sys     0m1.540s

Note: Uses ~6 GiB of memory for a 1 GiB file.

markp-fuso #1

$ time sh -c 'tac test.dat | awk -v new_dat="new.dat" '\''1;/\.Ends/ && !(seen++) {system("tac " new_dat)}'\'' | tac >test_copy.dat'

real    0m27.060s
user    0m25.874s
sys     0m6.544s

$ time sh -c 'tac test.dat | awk -v new_dat="new.dat" '\''1;/\.Ends/ && !(seen++) {system("tac " new_dat)}'\'' | tac >test_copy.dat'

real    0m28.995s
user    0m25.365s
sys     0m6.195s

markp-fuso #2

$ time awk -v new_dat="new.dat" 'FNR==NR { if ($0 ~ /\.Ends/) lastline=FNR; next} FNR==lastline { system("cat "new_dat)
}; 1' test.dat test.dat >test_copy.dat

real    0m53.121s
user    0m52.400s
sys     0m0.700s

$ time awk -v new_dat="new.dat" 'FNR==NR { if ($0 ~ /\.Ends/) lastline=FNR; next} FNR==lastline { system("cat "new_dat) }; 1' test.dat test.dat >test_copy.dat

real    0m53.079s
user    0m52.285s
sys     0m0.770s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment