DEV Community

Cover image for How fast is your code?

How fast is your code?

Duc Ng on October 04, 2018

One of the key metrics when writing code is speed. But there is no convenient way to measure the speed of your code efficiently so far. Chrome and ...
Collapse
 
bgadrian profile image
Adrian B.G. • Edited

Lighting McQueen fast

Other devs can read my code very fast 😁

I presume you talk about browsers, for backend we have performant choices.

You should also check out Flamegraphs charts, and Dev tools have very mature performance monitoring and analysis tools.

Having the words JavaScript and performance in the same article feels .. weird.

Engines developers, same as JVM and probably .net optimize their engines based on most common practices, so if you write good enough code it will run fast. V8 team have some good talks on youtube about this topic.

Collapse
 
ngduc profile image
Duc Ng

Actually, it's not weird. APM for NodeJS is a whole business.

Collapse
 
bgadrian profile image
Adrian B.G.

If a team wants performance for its key components and paths will not use nodeJS, it can only go so far ...

Collapse
 
thomasjunkos profile image
Thomas Junkツ

When doing JS benchmarks ...
youtube.com/watch?v=r76ZjdzFExg

Collapse
 
ngduc profile image
Duc Ng

Great talk & insight. It's like a C dev explained JS perf at byte code level.

Collapse
 
thomasjunkos profile image
Thomas Junkツ

AFAIR he worked on the V8 JS engine ;)

Collapse
 
gmartigny profile image
Guillaume Martigny

Benchmarking is a skill on its own. Today's JS engine use a lot of shortcut and optimization, which impact performance tests.
It's also a balance between clear and maintainable code against fast and optimizable code. With modern computer power, I would largely prefer the first side.

Also, to measure time I would use developer.mozilla.org/docs/Web/API...

Collapse
 
ngduc profile image
Duc Ng

Right. console.time is useful for one time use.
If you want to capture measured data, store, analyze, visualize them, etc. then that's not enough.

Collapse
 
xuwupeng2000 profile image
Jack Wu

As fast as your CPU. The performance limitations are CPU, GPU, all sort of processors but not my dear code. 🙌

Collapse
 
ngduc profile image
Duc Ng

Maybe DB connections, queries, rendering libs/functions, array lookup, etc. So many factors to measure.

Collapse
 
ngduc profile image
Duc Ng

Can't wait for native JS become true (WebAssembly, asm.js. Nectarjs looks promising).
Meanwhile, I will stick with JS :)

Collapse
 
nektro profile image
Meghan (she/her)

Wasm is not a replacement for JS unfortunately

Thread Thread
 
ngduc profile image
Duc Ng

I agree.

Thread Thread
 
qm3ster profile image
Mihail Malo

@nektro that's just political propaganda.
In reality, it will probably replace it, not only in libraries but all the way to the glue code.
Just needs more features than the MVP release we have now.
But they are definitely on the way.

Collapse
 
thomasjunkos profile image
Thomas Junkツ

My sarcasm detector isn't working right now...