Skip to content

Commit a633503

Browse files
authored
Update fn.getTime() helper for op/s
* install tinydate * replace inline "getTime" helper; 1M op/s --> 75M op/s * minor cleanup * uninstall tinydate * replace with new inline helper; 18M op/s
1 parent ad8a0ba commit a633503

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

lib/boot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict"
22

3-
const Promise = require('bluebird');
3+
const Promise = require('bluebird')
44

55
function deferAll(obj) {
66
const o = {}

lib/fn.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ $.formatTime = arr => {
2727

2828
/**
2929
* Get the current time!
30-
* @return {String} Formatted as `HH:MM:ss`.
30+
* @return {String} Formatted as `[HH:mm:ss]`.
3131
*/
32-
$.getTime = () => new Date().toTimeString("UTC").match(/[^\s]+/)[0]
32+
const pad = n => (n < 10 ? "0" + n : n)
33+
$.getTime = () => {
34+
const d = new Date()
35+
return `[${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}]`
36+
}
3337

3438
/**
3539
* Check if value is unique within the group. Modify if is not.

lib/plugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict"
22

33
const p = require("path")
4-
const isObject = require("./fn").isObject
54
const flatten = require("./fn").flatten
5+
const isObject = require("./fn").isObject
66
const co = require("bluebird").coroutine
77
const $ = require("./utils")
88

lib/utils/logging.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function stamp() {
3131
// }
3232

3333
// print the curr time.
34-
process.stdout.write(`[${clor[this.color](getTime())}] `)
34+
process.stdout.write(clor[this.color](getTime()) + " ")
3535

3636
// apply arguments to `console` method
3737
console[this.method].apply(console, (this.custom ? [this.custom].concat(args) : args))

test/fn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ test("fn.getTime", t => {
8282
const out = $.getTime()
8383
t.equal(typeof out, "string", "returns a string")
8484
t.equal(out.split(":").length, 3, "has 3 segments")
85-
t.equal(out.length, 8, "is always 8 characters long")
85+
t.equal(out.length, 10, "is always 10 characters long")
8686
t.end()
8787
})
8888

0 commit comments

Comments
 (0)