Guest User

Raku Date Parse Benchmark

a guest
Sep 10th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.71 KB | Source Code | 0 0
  1. #!/usr/bin/env raku
  2.  
  3. use Bench;
  4.  
  5. grammar MyDateFormat {
  6.     regex TOP {
  7.         <year=.d4> <month=.d2> <day=.d2> <hour=.d2> <minute=.d2> <second=.d2>
  8.         { make DateTime.new(|$/) }
  9.     }
  10.     regex d2 { \d**2 }
  11.     regex d4 { \d**4 }
  12. }
  13.  
  14. my constant $s = '20250910130537';
  15.  
  16. my %subs = (
  17.     match   => sub { DateTime.new: |$s.match(/(....)(..)(..)(..)(..)(..)/) },
  18.     rotor   => sub { DateTime.new: |$s.comb.rotor(4,2,2,2,2,2)».join },
  19.     grammar => sub { MyDateFormat.parse($s).made },
  20.     substr  => sub { DateTime.new(.substr(0,4),.substr(4,2),.substr(6,2),.substr(8,2),.substr(10,2),.substr(12,2)) given $s },
  21. );
  22.  
  23. say .key.fmt('%10s') => (.value)() for %subs;
  24.  
  25. Bench.new.cmpthese(1e5, %subs)
Tags: raku
Advertisement
Add Comment
Please, Sign In to add comment