Rails Rails Time.zone.now 性能小增

zzxworld · October 14, 2016 · Last by lgn21st replied at October 14, 2016 · 1724 hits

https://github.com/rails/rails/pull/26359

Warming up --------------------------------------
            Time.now   127.923k i/100ms
       Time.zone.now    10.275k i/100ms
Calculating -------------------------------------
            Time.now      1.946M (± 5.9%) i/s -      9.722M in   5.010236s
       Time.zone.now    106.625k (± 4.3%) i/s -    534.300k in   5.020343s

Comparison:
            Time.now:  1946220.1 i/s
       Time.zone.now:   106625.5 i/s - 18.25x slower

TL;DR

看代码提交,貌似是通过减少创建重复的 Time 对象实现的。

You need to Sign in before reply, if you don't have an account, please Sign up first.