function vs expression vs arrow definitions - Performance comparison (Part 3)
Manoj

Manoj @manojadams

About: Senior engineer at Wealthy

Joined:
Aug 1, 2023

function vs expression vs arrow definitions - Performance comparison (Part 3)

Publish Date: Aug 16 '23
1 0

In this post we are going to compare performance of javascript functions created with function definitions vs function expressions vs arrow functions.

To test this, we created three types of files:

  • withFunctionDefinition.js - contains simple function definitions
  • withFunctionExpression.js - contains function definitions using function expression syntax
  • withArrowDefinition.js - contains function definitions with arrow syntax

withFunctionDefinition

  • Lets create a file with name withFunctionDefinition.js and add 1 million function definitions to the file.

withFunctionExpression

  • Lets create another file with name withFunctionExpression.js and add 1 million function definitions using expressions to the file.

withArrowDefinition

  • Lets create yet another file with name withArrowDefinition.js and add 1 million arrow functions.

Results

  • File withFunctionDefinition takes a constant time to get executed and has the best overall performance.
  • The time complexity of files withFunctionExpression and withArrowDefinition grows linearly alongwith number of functions defined in the file (and both are similar)

References

https://github.com/manojadams/js-objects-memory/blob/main/function-definition_vs_function-expression_vs_arrow-function/README.md

Comments 0 total

    Add comment