https://github.com/stringmanolo/javascript-performance-study
Finding the fastest way to do things
https://github.com/stringmanolo/javascript-performance-study
Last synced: 6 months ago
JSON representation
Finding the fastest way to do things
- Host: GitHub
- URL: https://github.com/stringmanolo/javascript-performance-study
- Owner: StringManolo
- Created: 2021-05-26T16:44:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-31T06:27:18.000Z (over 4 years ago)
- Last Synced: 2025-05-31T20:51:38.806Z (8 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# javascript-performance-study
Finding the fastest way to do things
Android 10; ART-L29 Build HUAWEIART-L29
## Clone Simple Objects
Config:
```Cloning 1.000.000 times```
#### Chrome (88.0.4324.152)
| Method | Time |
| :-----------: | :----------: |
| JSON | 2.069 s |
| Assign Props | 0.163 s |
| Object.assign | 1.488 s |
#### Firefox (Nightly 210310)
| Method | Time |
| :-----------: | :----------: |
| JSON | 3.116 s |
| Assign Props | 0.162 s |
| Object.assign | 0.460 s |
#### Node (v14.15.4)
| Method | Time |
| :-----------: | :----------: |
| JSON | 3.833 s |
| Assign Props | 0.179 s |
| Object.assign | 3.080 s |
#### Quickjs (v2020-11-08)
| Method | Time |
| :-----------: | :----------: |
| JSON | 7.820 s |
| Assign Props | 2.508 s |
| Object.assign | 1.604 s |
Winner:
```js
// Assign Props
const cloneObject = obj => {
let clone = {};
for(let key in obj) {
clone[key] = obj[key];
}
return clone;
}
```
Loser:
```js
// JSON
const cloneObject = obj => {
let clone = JSON.parse(JSON.stringify(obj));
return clone;
}
```
## Add 2 strings
Config:
```Adding 1.000.000 times```
#### Chrome (88.0.4324.152)
| Method | Time |
| :-----------: | :----------: |
| += | 0.191 s |
| [].push(1) | 0.308 s |
| [].push(2) | 0.312 s |
| "".concat() | 0.248 s |
#### Firefox (Nightly 210310)
| Method | Time |
| :-----------: | :----------: |
| += | 0.068 s |
| [].push(1) | 0.142 s |
| [].push(2) | 0.261 s |
| "".concat() | 0.502 s |
#### Node (v14.15.4)
| Method | Time |
| :-----------: | :----------: |
| += | 0.412 s |
| [].push(1) | 0.373 s |
| [].push(2) | 0.291 s |
| "".concat() | 0.197 s |
#### Quickjs (v2020-11-08)
| Method | Time |
| :-----------: | :----------: |
| += | slow s |
| [].push(1) | 0.666 s |
| [].push(2) | 0.432 s |
| "".concat() | 0.773 s |
Winner:
```js
const addStrings = (s1, s2) => s1 + s2;
```
Loser:
```js
const addStrings = (s1, s2) => s1.concat(s2);
```
## lib/perfFunctions.mjs
Module implementing the faster functions