Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
More Decks by karupanerura
See All by karupanerura
音を出したい
karupanerura
0
100
Perl Meets \w+ あるいは開発を支えるPerl活用の実例集
karupanerura
0
79
log
karupanerura
1
110
Use Perl as Better Shell Script
karupanerura
0
930
GoでParserを書く
karupanerura
4
1.1k
マイ隙間家具OSSたちのご紹介
karupanerura
2
300
Mustache Template 話 2024
karupanerura
0
69
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
3.7k
Javaの実装をPerlでテストする
karupanerura
0
1.4k
Other Decks in Technology
See All in Technology
CTOキーノート:AI時代の「つなぐ」を再定義 ― 真のIoTとリアルワールドAI【SORACOM Discovery 2026】
soracom
PRO
0
240
A Bag-of-Documents Model for Query Specificity
dtunkelang
0
110
Git 研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
610
人とエージェントが高め合う協業設計
kintotechdev
0
990
13年運用タイトルのサーバーサイドが辿り着いた現在地 ― モンスターストライクにおける技術・組織・AI活用から得た知見
mixi_engineers
PRO
1
180
歴史から理解するクラウドインフラのしくみ
kizawa2020
0
180
WEBフロントエンド研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
460
reFACToring
moznion
1
700
VPCセキュリティ対応の最新事情
nagisa53
1
340
「待ち時間」の消滅と「自我消耗」の加速:生成AI時代のエンジニアを救うメンタル・リソース管理
poropinai1966
0
230
Multicaで30個のミニプロジェクトをAIエージェント運用して見えてきたこと
eiei114
1
680
現場で使える AWS DevOps Agent 活用ノウハウ - Release Management 機能の検証結果を添えて / AWS DevOps Agent Release Management and Know-How
kinunori
3
210
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
The Curse of the Amulet
leimatthew05
2
13k
Designing Experiences People Love
moore
143
24k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Design in an AI World
tapps
1
270
Navigating Weather and Climate Data
rabernat
0
410
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Transcript
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ศར
͋Γ͕ͱ͏͍͟͝·ͨ͠