SlideShare une entreprise Scribd logo
1  sur  21
Kansai.pm #16
id:karupanerura
Time::Moment
+ Time::Strptime
= 💪
About me
• Kenta SATO (id:karupanerura)
• Perl/Go/Swift/Kotlin/Java/Crystal/C99/etc..
• Gotanda.pm Author
• Senior Engineer at Mobile Factory, Inc.
• WebApp/iOS/Android/Operation/etc..
日時処理
日時処理
• 日付や時刻に関する処理
• 単純な計算にならない
• タイムゾーン
• うるう年/うるう秒
• 月またぎ
タイムゾーン
• 時差を管理する概念
• UTC(世界標準時)からの時差=>オフセット
• 地域ごとに決まっている
• (現在の)日本だったら全域JST-9(Asia/Tokyo)
• サマータイムもタイムゾーンで管理
Yokohama.pm #10
http://www.slideshare.net/karupanerura/yokohamapm-10
Time::Moment
Time::Moment
• 日時処理モジュール
• シンプル
• 高速
• 不変性
シンプル
• 固定オフセットのみをサポート
• サマータイムなどは考慮しない
• 秒ベースで計算
高速
• 基本的に全ての処理がCで書かれている
• c-dt というCライブラリのPerlバインディング
不変性
• 同じインスタンスは必ず同一の日時を指す
• 副作用が最小限になる
どれくらい速いか
=> DEMO
弱点
Time::Momentの弱点
• 任意フォーマットの日付のparseが不可能
• from_stringはあるがフォーマットは固定
• システムのタイムゾーン/ロケールに依存
Time::Momentの弱点
• 任意フォーマットの日付のparseが不可能
• from_stringはあるがフォーマットは固定
• システムのタイムゾーン/ロケールに依存
↑ Time::Strptime
↑DateTimeX::Moment
Time::Strptime
Time::Strptime
• 拙作の汎用のstrptime実装
• Pure Perlで動く
• 高速
• 昨日、1.00が出ました
YAPC::EU 2015http://www.slideshare.net/karupanerura/optimize-perl5-code-for-perfomance-freaks
Time::Momentと組み合わせる
• Time::Momentでstrptimeできるようになる!
• 弱点がひとつ解決!
DEMO
まとめ
• Time::Momentは良い
• Time::Strptimeと組み合わせると最強
• 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪 💪

Contenu connexe

Plus de karupanerura

モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤
karupanerura
 
mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lock
karupanerura
 

Plus de karupanerura (20)

Perl5 VS JSON
Perl5 VS JSONPerl5 VS JSON
Perl5 VS JSON
 
コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良く
 
The plan of Aniki 2.0
The plan of Aniki 2.0The plan of Aniki 2.0
The plan of Aniki 2.0
 
Aniki::Internal
Aniki::InternalAniki::Internal
Aniki::Internal
 
The Crystal language *recently* update
The Crystal language *recently* updateThe Crystal language *recently* update
The Crystal language *recently* update
 
KOWAZA for mackerel
KOWAZA for mackerelKOWAZA for mackerel
KOWAZA for mackerel
 
Optimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaksOptimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaks
 
Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術
 
router-simple.cr
router-simple.crrouter-simple.cr
router-simple.cr
 
Why we use mruby with Perl5?
Why we use mruby with Perl5?Why we use mruby with Perl5?
Why we use mruby with Perl5?
 
はかたの塩
はかたの塩はかたの塩
はかたの塩
 
Gotanda.pmの紹介
Gotanda.pmの紹介Gotanda.pmの紹介
Gotanda.pmの紹介
 
すいすいSwift
すいすいSwiftすいすいSwift
すいすいSwift
 
Perlにおけるclass実装パターン
Perlにおけるclass実装パターンPerlにおけるclass実装パターン
Perlにおけるclass実装パターン
 
モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤
 
Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programming
 
mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lock
 
dwangocpp1-lt
dwangocpp1-ltdwangocpp1-lt
dwangocpp1-lt
 
engineer-life
engineer-lifeengineer-life
engineer-life
 

TIme::Moment+Time::Strptime=