Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__spread Performance Issues #125

Open
Zclhlmgqzc opened this issue Aug 27, 2020 · 2 comments
Open

__spread Performance Issues #125

Zclhlmgqzc opened this issue Aug 27, 2020 · 2 comments

Comments

@Zclhlmgqzc
Copy link

Zclhlmgqzc commented Aug 27, 2020

__spread

var tslib = require("tslib");
const { concat } = require('lodash')

var testPushES6 = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    const arr = arr1.push(...arr2)
}

var testPush = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    Array.prototype.push.apply(arr1, arr2)
}

var testPush2 = function(flag) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    arr1.push.apply(arr1, tslib.__spread(arr2));
}

var testConcat = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    var arr  = arr1.concat(arr2)
  }

var testConcat = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    var arr  = concat(arr1, arr2)
  }

var count = 1000000

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPushES6()
}
// 136
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPush()
}
// 139
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPush2()
}
// 1005
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testConcat()
}
// 310
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testConcat2()
}
// 810
console.log(Date.now() - date)
@Zclhlmgqzc
Copy link
Author

see #133

@Zclhlmgqzc Zclhlmgqzc reopened this Mar 5, 2021
@Zclhlmgqzc
Copy link
Author

arr1.push.apply(arr1, tslib.__spreadArray([], tslib.__read(arr2)))

is 15% faster than

arr1.push.apply(arr1, tslib.__spread(arr2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant