diff --git a/benchmark/time_now.yml b/benchmark/time_now.yml new file mode 100644 index 0000000000..f6d6a31489 --- /dev/null +++ b/benchmark/time_now.yml @@ -0,0 +1,3 @@ +benchmark: + - 'Time.now' + - 'Time.now(in: "+09:00")' diff --git a/time.c b/time.c index 77f42fc89a..3a004f8763 100644 --- a/time.c +++ b/time.c @@ -1931,6 +1931,13 @@ time_init_now(rb_execution_context_t *ec, VALUE time, VALUE zone) return time; } +static VALUE +time_s_now(rb_execution_context_t *ec, VALUE klass, VALUE zone) +{ + VALUE t = time_s_alloc(klass); + return time_init_now(ec, t, zone); +} + static VALUE time_set_utc_offset(VALUE time, VALUE off) { diff --git a/timev.rb b/timev.rb index 52056f4e59..892740c5a2 100644 --- a/timev.rb +++ b/timev.rb @@ -221,7 +221,7 @@ class Time # Parameter: # :include: doc/time/in.rdoc def self.now(in: nil) - new(in: Primitive.arg!(:in)) + Primitive.time_s_now(Primitive.arg!(:in)) end # _Time_