Skip to content

50 times slower than Date.parse #430

@forthrin

Description

@forthrin

Needed to parse (Yesterday, Today, Tomorrow, Monday .. Sunday) relative to a given date.

Anyone knows how to:

  • Speed up this library to match Date.parse
  • Another library that can do this? (Except Rails)
$ time ruby -rtime -rchronic -rprofile -e "1000.times { Date.parse('Monday') }" 2>&1 | head
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 51.74     0.02      0.02     1000     0.02     0.03  Date.parse
 15.81     0.03      0.01        1     5.99    36.49  Integer#times
  6.86     0.03      0.00     1000     0.00     0.03  nil#
  3.68     0.03      0.00     1000     0.00     0.00  Regexp#match
  2.90     0.03      0.00     1000     0.00     0.00  MatchData#begin
  2.45     0.03      0.00     1000     0.00     0.00  String#gsub!
  2.21     0.03      0.00     1000     0.00     0.00  MatchData#end
  2.07     0.03      0.00     1000     0.00     0.00  String#[]=
0m0.134s

$ time ruby -rtime -rchronic -rprofile -e "1000.times { Chronic.parse('Monday') }" 2>&1 | head
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 19.92     1.25      1.25   131000     0.01     0.08  Chronic::Handler#match
 18.77     2.43      1.18   199000     0.01     0.01  Chronic::Handler#tags_match?
 10.97     3.12      0.69    64000     0.01     0.03  Chronic::Numerizer.numerize
  5.91     3.49      0.37    57000     0.01     0.18  Array#each
  5.37     3.83      0.34    49000     0.01     0.01  String#gsub
  5.16     4.15      0.32    61000     0.01     0.01  Chronic::Tag.scan_for
  2.96     4.34      0.19   306000     0.00     0.00  Array#[]
  2.12     4.47      0.13    50000     0.00     0.06  Array#each_index
0m7.419s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions