3. About me
• Kenta SATO (@karupanerura)
• Senior Engineer at Mobile Factory, Inc.
• WebApp/iOS/Android/Operation/etc..
• Perl/Swift/Kotlin/Java/Crystal/XS/C99/etc..
• Gotanda.pm Author
16. strptime(3)
• Parse date time string using arbitrary format
• e.g.) “%Y-%m-%d %H:%M:%S”
=> “2015-09-04 12:00:00”
17. Choices in Perl5
• DateTime::Format::Strptime (PP)
• Time::Piece->strptime (XS)
• POSIX::strptime (XS)
• Time::Strptime (PP)
• Time::Moment (fixed format but very fast)
18. Time::Strptime
• Pure Perl implementation
• If Time::TZOffset is installed, make it faster
• Using Time::Local for caluclating epoch
• Using system timezone
• Using system locale
25. Suppress memory copy
• Use constant.pm if possible
• for constant folding
• Use perl 5.20 or later
• String COW is available
• experimental::refaliasing
26. experimental::refaliasing
• Enables aliasing via assignment to references
• Example: my $bar = $foo
• Makes alias $bar to $foo
• (pointer to same memory)
• Available on perl 5.22 or later
27. experimental::refaliasing
• But, Not fast… (why…?)
• Copying is 63% faster than refaliasing
• When copying|refaliasing IV value
• I believe that refaliasing will be faster than
copying in near future :)
28. Optimize regular expressions
• Less slow expressions
• Character Class < Quantifiers < Grouping
• e.g.) Less matching patterns of regexp
• e.g.) /A[0-5][0-9]z/m
• This is 6% faster than /A[0-9]{2}z/m
30. Instance cache
• Time::Strptime reuses instances
• Often times the same format is used
• So cached instance can be used
• Pay format parsing cost only once
• Caching is enabled by default
31. String eval
• Used to avoid conditional statements.
• Pay the cost of generating code instead of at
runtime
• (DEMO)
32. String eval
• Warning: very DANGEROUS!!
• If you use it in your code, you should write
many tests