Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env raku
- use Bench;
- grammar MyDateFormat {
- regex TOP {
- <year=.d4> <month=.d2> <day=.d2> <hour=.d2> <minute=.d2> <second=.d2>
- { make DateTime.new(|$/) }
- }
- regex d2 { \d**2 }
- regex d4 { \d**4 }
- }
- my constant $s = '20250910130537';
- my %subs = (
- match => sub { DateTime.new: |$s.match(/(....)(..)(..)(..)(..)(..)/) },
- rotor => sub { DateTime.new: |$s.comb.rotor(4,2,2,2,2,2)».join },
- grammar => sub { MyDateFormat.parse($s).made },
- substr => sub { DateTime.new(.substr(0,4),.substr(4,2),.substr(6,2),.substr(8,2),.substr(10,2),.substr(12,2)) given $s },
- );
- say .key.fmt('%10s') => (.value)() for %subs;
- Bench.new.cmpthese(1e5, %subs)
Advertisement
Add Comment
Please, Sign In to add comment