Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Inside of Time::Strptime
Search
karupanerura
July 05, 2018
Technology
1.8k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Inside of Time::Strptime
Shibuya.pm #18 LT
karupanerura
July 05, 2018
Transcript
17 slides
Inside of Time::Strptime id:karupanerura Shibuya.pm #18 LT
Time::Strptime
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
Time::Strptime • strptime(3) ͷ Pure Perl ࣮ • Time::MomentͰҙϑΥʔϚοτͷύʔε͕ Ͱ͖ͳ͔ͬͨͷͰ࡞ͬͨ
• ߴ
Pure Perlͳͷʹߴʁʁʁ
ϕϯνϚʔΫ
݅ • OS X High Sierra • Perl 5.28.0 •
Time::Local: 1.28 • Time::Moment: 0.44 • Time::Piece: 1.3204 • Time::Strptime: 1.03
݅ • %Y-%m-%d %H:%M:%S Ͱparse͢Δ • epochͱoffsetΛऔಘ • ParserΩϟογϡͯ͠ྑ͍(cachedͱ໌ه) •
GMTͰ࣮ߦ(offsetܭࢉͷ࠷దԽՄೳ)
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)
݁Ռ • Time::Piece(cached)ʹରͯ͠231%ߴ • POSIX::strptimeʹରͯ͠10% • ※DateTimeൺֱͷܻ͕ҧ͏ͷͰআ֎ͯ͠Δ • ͓ͦ͗͢Δ
ͳ͍ͥʁ
Ξϓϩʔν • ࠷దԽͨ͠ίʔυΛੜͯ͠Ωϟογϡ • ذͱϝϞϦΞϩέʔγϣϯΛ࠷খԽ • ಉ͡Ξϓϩʔνͷ࣮ • Text::MicroTemplate •
Apache::LogFormat::Compiler
ੜίʔυྫ 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); };
͜ΕΛText Evalͯ݁͠Ռͷ CodeRefΛΩϟογϡ
͍ʂʂʂʂʂʂ
·ͱΊ evalศར
͋Γ͕ͱ͏͍͟͝·ͨ͠
More Decks by karupanerura
See All by karupanerura
音を出したい
karupanerura
0
160
Perl Meets \w+ あるいは開発を支えるPerl活用の実例集
karupanerura
0
110
log
karupanerura
1
130
Use Perl as Better Shell Script
karupanerura
0
990
GoでParserを書く
karupanerura
4
1.1k
マイ隙間家具OSSたちのご紹介
karupanerura
2
330
Mustache Template 話 2024
karupanerura
0
89
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
4.7k
Javaの実装をPerlでテストする
karupanerura
0
1.5k
Other Decks in Technology
See All in Technology
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
MCPでネットワーク障害調査を自動化する前に直すべき3つのこと
yama3133
0
240
BALLAS Technology Deck
ballas_inc
0
620
Agent Harnessはどう作る?事例から学ぶAI Agentの設計思想
sergicalsix
0
300
Frontier Teams — Amazon は AI で「開発のやり方」をどう変えたのか
kmotohas
0
260
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
440
Steering と Hook (チームの決まりを守らせる) | 目指せ Kiro マスター 06
inariku
PRO
2
130
Intro to Kiro (One agent, every surface) | Kiro: Zero to Hero 01
inariku
PRO
2
130
複数システムが同居した 15 年物の AWS アカウントを解体するための考古学
wa6sn
3
150
Kiro を使うコツ (頼み方、覚えさせ方、任せ方) | 目指せ Kiro マスター 09
inariku
PRO
3
160
「任されビリティ」で引き受けて「よしなりてぃ」に頼らず任せる / Accept tasks with "makasarebility" and hand them over without relying on "yoshinarily"
pauli
0
580
DevOps Agentにあらゆるセキュリティインシデントのトリアージを任せた件
jirtosterone
1
150
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
570
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
The SEO Collaboration Effect
kristinabergwall1
1
620
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
310
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Fireside Chat
paigeccino
43
4.1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
330
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
WCS-LA-2024
lcolladotor
0
1k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k