Are javascript caching operations?

I performed the Levenshtein distance function in Javascript, and I was wondering how long it would take to run it using the Wikedia example (Sunday and Saturday).

So I used console.time(), and console.timeEnd()to determine the time spent on this function.

for (var i = 0; i < 15; i++) {
    console.time("benchmark" + i);
    var result = LevenshteinDistance("sunday", "saturday");
    console.timeEnd("benchmark" + i);
}

Since it ranged between 0.4 ms and 0.15 ms, I used a loop and I came across strange values:

  • 0.187ms
  • 0.028ms
  • 0.022ms
  • 0.022ms
  • 0.052ms
  • 0.026ms
  • 0.028ms
  • 0.245ms
  • 0.030ms
  • 0.024ms
  • 0.020ms
  • 0.019ms
  • 0.059ms
  • 0.039ms
  • 0.040ms

A repeating thing is a high value for the first (and rarely the second) performance, and then lower values. (Same behavior between JS in Chrome console and NodeJS.)

, : "" Javascript ( JS V8)?

?

+4
1

V8 JIT. , , , , , , , .

? . , , , , , . JavaScript - Node.js hello world Java hello world (, Node.js , ).

Node.js, hello.js:

console.log('Hello from Node');

Java, Hello.java:

class Hello {
    public static void main(String[] argv) {
        System.out.println("Hello from Java");
    }
}

Node:

$ time (node hello.js)
Hello from Node

real    0m0.059s
user    0m0.047s
sys 0m0.012s

Java:

$ time (javac Hello.java && java Hello)
Hello from Java

real    0m0.554s
user    0m1.073s
sys 0m0.068s

.:

+5

Source: https://habr.com/ru/post/1671622/


All Articles