Slide 1

Slide 1 text

Inside of Time::Strptime id:karupanerura Shibuya.pm #18 LT

Slide 2

Slide 2 text

Time::Strptime

Slide 3

Slide 3 text

use Time::Strptime qw/strptime/; # function my ($epoch_f, $offset_f) = strptime('%Y-%m-%d %H:%M:%S', '2014-01-01 00:00:00'); # OO style my $fmt = Time::Strptime::Format->new('%Y-%m-%d %H:%M:%S'); my ($epoch_o, $offset_o) = $fmt->parse('2014-01-01 00:00:00'); Time::Strptime

Slide 4

Slide 4 text

Time::Strptime • strptime(3) ͷ Pure Perl ࣮૷ • Time::MomentͰ೚ҙϑΥʔϚοτͷύʔε͕ Ͱ͖ͳ͔ͬͨͷͰ࡞ͬͨ • ߴ଎

Slide 5

Slide 5 text

Pure Perlͳͷʹߴ଎ʁʁʁ

Slide 6

Slide 6 text

ϕϯνϚʔΫ

Slide 7

Slide 7 text

৚݅ • OS X High Sierra • Perl 5.28.0 • Time::Local: 1.28 • Time::Moment: 0.44 • Time::Piece: 1.3204 • Time::Strptime: 1.03

Slide 8

Slide 8 text

৚݅ • %Y-%m-%d %H:%M:%S Ͱparse͢Δ • epochͱoffsetΛऔಘ • Parser͸Ωϟογϡͯ͠ྑ͍(cachedͱ໌ه) • GMTͰ࣮ߦ(offsetܭࢉͷ࠷దԽ͸Մೳ)

Slide 9

Slide 9 text

Benchmark: running pt, tm, tp, tp(cached), ts(cached) for at least 10 CPU seconds... pt: 11 wallclock secs (10.41 usr + 0.01 sys = 10.42 CPU) @ 297345.59/s (n=3098341) tm: 10 wallclock secs (10.17 usr + 0.01 sys = 10.18 CPU) @ 2481673.28/s (n=25263434) tp: 10 wallclock secs (10.52 usr + 0.01 sys = 10.53 CPU) @ 56390.98/s (n=593797) tp(cached): 11 wallclock secs (10.53 usr + 0.01 sys = 10.54 CPU) @ 80838.24/s (n=852035) ts(cached): 11 wallclock secs (10.60 usr + 0.01 sys = 10.61 CPU) @ 267686.15/s (n=2840150) Rate tp tp(cached) ts(cached) pt ™ tp 56391/s -- -30% -79% -81% -98% tp(cached) 80838/s 43% -- -70% -73% -97% ts(cached) 267686/s 375% 231% -- -10% -89% pt 297346/s 427% 268% 11% -- -88% tm 2481673/s 4301% 2970% 827% 735% -- tp=Time::Piece(XS) ts=Time::Strptime(PP) pt=POSIX::strptime tm=Time::Moment(XS)

Slide 10

Slide 10 text

݁Ռ • Time::Piece(cached)ʹରͯ͠231%ߴ଎ • POSIX::strptimeʹରͯ͠10%௿଎ • ※DateTime͸ൺֱͷܻ͕ҧ͏ͷͰআ֎ͯ͠Δ • ͓ͦ͗͢Δ

Slide 11

Slide 11 text

ͳͥ଎͍ʁ

Slide 12

Slide 12 text

Ξϓϩʔν • ࠷దԽͨ͠ίʔυΛੜ੒ͯ͠Ωϟογϡ • ෼ذͱϝϞϦΞϩέʔγϣϯΛ࠷খԽ • ಉ͡Ξϓϩʔνͷ࣮૷ • Text::MicroTemplate • Apache::LogFormat::Compiler

Slide 13

Slide 13 text

ੜ੒ίʔυྫ my ($year, $month, $day, $hour24, $minute, $second, $offset, $epoch); $offset = 0; sub { ($year, $month, $day, $hour24, $minute, $second) = $_[0] =~ m{\A([0-9]{4})\-(0[1-9]|1[0-2])\-(0[1-9]|[12] [0-9]|3[01])T([01][0-9]|2[0-3])\:([0-5][0-9])\:([0-5][0-9]| 60)\z}mo or Carp::croak 'cannot parse datetime. text: "'. $_[0].'", format: '."\"%FT%T\""; $epoch = timegm_nocheck($second, $minute, $hour24, $day, $month - 1, $year); $offset = $time_zone->offset($epoch); $epoch -= $offset; ($epoch, $offset); };

Slide 14

Slide 14 text

͜ΕΛText Evalͯ݁͠Ռͷ CodeRefΛΩϟογϡ

Slide 15

Slide 15 text

଎͍ʂʂʂʂʂʂ

Slide 16

Slide 16 text

·ͱΊ eval͸ศར

Slide 17

Slide 17 text

͋Γ͕ͱ͏͍͟͝·ͨ͠