Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Inside of Time::Strptime
karupanerura
July 05, 2018
Technology
1
1.3k
Inside of Time::Strptime
Shibuya.pm #18 LT
karupanerura
July 05, 2018
Tweet
Share
More Decks by karupanerura
See All by karupanerura
Japan.pm 2021 開催まで至る道
karupanerura
0
53
Perl MongersのためのAWS_CDK入門
karupanerura
0
57
Webシステムのパフォーマンス・チューニング
karupanerura
2
490
WebシステムのパフォーマンスとGo
karupanerura
3
1.1k
タイムテーブルを楽に組みたい
karupanerura
0
1.8k
アマチュアレコーディングエンジニアリング失敗談
karupanerura
6
370
ISUCON8予選問題出題の裏側
karupanerura
0
5.1k
遠いようで身近なサウンドエンジニアリング
karupanerura
5
15k
perldoc(?:\.jp)?
karupanerura
0
100
Other Decks in Technology
See All in Technology
⚡Lightdashを試してみた
k_data_analyst
0
110
HTTP Session Architecture Pattern
chiroito
1
350
20220510_簡単にできるコスト異常検出(Cost Anomaly Detection) /jaws-ug-asa-cost-anomaly-detection-20220510
emiki
2
310
Babylon.js v5 新機能の紹介
limes2018
0
600
New Features in C# 10/11
chack411
0
590
開発者のための GitHub Organization の安全な運用と 継続的なモニタリング
flatt_security
2
1.7k
CADDi HCMC Technology Center
caddi_eng
0
210
The Real MVP: Going from idea to users' hands
adavis
0
580
成長を続ける組織でのSRE戦略:プレモーテムによる信頼性の認識共有 SRE Next 2022
niwatakeru
7
2.1k
【OCHaCafe#5】その Pod 突然落ちても大丈夫ですか?
k6s4i53rx
2
120
1年間のポストモーテム運用とそこから生まれたツール sre-advisor / SRE NEXT 2022
fujiwara3
5
2.7k
読者のことを考えて書いてみよう / Write with your reader in mind
line_developers
PRO
3
230
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
56
2.3k
GraphQLとの向き合い方2022年版
quramy
16
8k
Optimizing for Happiness
mojombo
365
63k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
12
890
Making Projects Easy
brettharned
98
4.3k
Docker and Python
trallard
27
1.5k
Stop Working from a Prison Cell
hatefulcrawdad
261
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
337
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.2k
We Have a Design System, Now What?
morganepeng
35
2.9k
Producing Creativity
orderedlist
PRO
333
37k
The Cult of Friendly URLs
andyhume
68
4.7k
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ศར
͋Γ͕ͱ͏͍͟͝·ͨ͠