moment-parse-date

JavaScript performance comparison

Test case created by ovcharik

Preparation code

<script src="//momentjs.com/downloads/moment-with-locales.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  const FAKE = moment()
  const TRAVELPORT_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSSZ'
  
  function parseTravelportDateOffset(input) {
    const hrs = +input.slice(23, 26)
    const mins = +input.slice(27, 29)
  
    return hrs * 60 + (hrs < 0 ? -mins : mins)
  }
  
  /**
   * Обрабатываются только даты формата ISO-8601, представленные в следующем виде:
   * - "2019-12-03T12:30:00.000-07:00"
   */
  function parseTravelportTimestamp(input) {
    const m = {}
    m.__proto__ = moment.prototype
  
    const offset = parseTravelportDateOffset(input)
    const date = new Date(input.slice(0, 23))
  
    m._isAMomentObject = true
    m._i = input
    m._f = TRAVELPORT_FORMAT
    m._tzm = offset
    m._isUTC = true
    m._locale = FAKE._locale
    m._d = date
    m._isValid = true
    m._offset = offset
  
    return m
  }

};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
moment format
moment("2019-12-03T14:05:00.000-07:00", "YYYY-MM-DDTHH:mm:ss.SSSSZ", true)
pending…
moment ISO-8601
moment("2019-12-03T14:05:00.000-07:00", moment.ISO_8601)
pending…
moment
moment("2019-12-03T14:05:00.000-07:00")
pending…
parseTravelportTimestamp
parseTravelportTimestamp("2019-12-03T14:05:00.000-07:00")
pending…
moment new Date
moment(new Date("2019-12-03T14:05:00.000-07:00"))
pending…
moment creationData
moment({
  input: "2019-12-03T14:05:00.000-07:00",
  format: "YYYY-MM-DDTHH:mm:ss.SSSSZ"
})
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments