6 ms·
console: The output console.timeEnd() and console.timeLog() will now automatically select a suitable time unit instead of always using milliseconds (Xavi
by simplyinfinity 7y ago
console:
The output console.timeEnd()
and console.timeLog()
will now automatically select a suitable time unit instead of always using milliseconds (Xavier Stouder) #29251
Am I the only one that finds this unacceptable? Instead of a consistent result of a number, let's return string.. That now I have to parse..
- CryoLogic 7y agoAgreed. That's a ridiculous change. A well defined function should have a single purpose, and a reliable and repeatable output.
- avarun 7y agoIt's a function on `console`. It's meant to be human-readable, not machine-readable.
- sundvor 7y agoConsole logging can be useful for eg being fed into Splunk from an ECS instance. I don't do node.js so perhaps there are other ways of doing that specifically. (Works great in .net core)
- _bxg1 7y agoIt doesn't output back into your code though; it goes directly to stdout, so its main priority is readability for debugging. If you need log-quality output for parsing by another program there are plenty of libraries for getting time in whatever format you wish.
- dickeytk 7y agoI think it’s ok, it’s just a debug statement that I think outputs to stderr. You should never be parsing it.
- simplyinfinity 7y agoShouldn't it be better to have a second function that spits out a formatted version? Or a parameter for a format. Or a parameter to switch between pretty and raw numbers?
- dickeytk 7y agono—this is something that likely shouldn't ever even be committed into a codebase. It's just something you throw in while testing to check why the performance of something is acting up. The default is really important for something like this. Much more important than consistency.
- Dashron 7y agoI looked at the code (but didnt try it) and I think this only affects console output, not any return value that you would parse.
- emilsedgh 7y agoI believe it rever really returned anything. It just wrote them on stdout. It's not an API incompatibility.
- bilalq 7y agoIt is a shift in the behavior of a side-effect though. Anyone who set up metric math based on log values here would be in for a surprise when they try to look at their reports. This is definitely one of the gray areas when deciding whether or not to consider it a breaking change.
- playpause 7y agoI agree it’s grey-area, but I’d lean towards calling it a breaking change, as it’s not too hard to imagine setups that would rely on a particular stdout format (e.g. some kind of log-parsing to generate an HTML report from an e2e test orchestration suite). But this is a major update, so breaking is fine anyway.
- snek 7y agoYou should not parse the stdout produced from console functions. It is for producing human-readable information. If you want machine-consumable data, you should use something like benchmark.js.
- nothrabannosir 7y agoHow far we have strayed from the days where Unix tools were meant to be used as a stdlib, called through stdin and out. It makes me a little sad. Classic HN comment on this topic: https://news.ycombinator.com/item?id=6530180 https://news.ycombinator.com/item?id=6530180
- snek 7y agoNot that far. Node has process.stdout/process.stdin/process.stderr. It's just that the console API is for debugging.
- BillinghamJ 7y agoThat's true of stderr output. You should be able to parse stdout though - otherwise how are you meant to use piping etc