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

Some test results are suspect. #71

Open
richardspence opened this issue Jun 14, 2019 · 2 comments
Open

Some test results are suspect. #71

richardspence opened this issue Jun 14, 2019 · 2 comments

Comments

@richardspence
Copy link

I noticed the destructuring tests for TS indicated 150X slower times than es5.

This is unusual because the emitted code is actually (almost) identical to the es5. The only difference is one additional variable declaration / assignment.

Emitted ts code for test: http://www.typescriptlang.org/play/index.html#src=var%20data%20%3D%20%7B%0D%0A%20%20a%3A%20'foo'%2C%0D%0A%20%20b%3A%20%7Bc%3A%20'd'%7D%2C%0D%0A%20%20arr%3A%20%5B1%2C%202%2C%203%5D%0D%0A%7D%3B%0D%0A%0D%0Afunction%20fn()%20%7B%0D%0A%20%20var%20%7Ba%2C%20b%3A%7Bc%3Ab%7D%2C%20arr%3A%5B%2C%20c%5D%7D%20%3D%20data%3B%0D%0A%20%20return%20c%3B%0D%0A%7D%0D%0A%0D%0AassertEqual(fn()%2C%202)%3B%0D%0Atest(fn)%3B

es5 test:

//emitted js from TS compiler
var data = {
    a: 'foo',
    b: { c: 'd' },
    arr: [1, 2, 3]
};
function fn() {
    var a = data.a, b = data.b.c, _a = data.arr, c = _a[1];
    return c;
}
assertEqual(fn(), 2);
test(fn);
//baseline es5
var data = {
  a: 'foo',
  b: {c: 'd'},
  arr: [1, 2, 3]
};

function fn() {
  var a = data.a,
      b = data.b.c,
      c = data.arr[1];
  return c;
}

assertEqual(fn(), 2);
test(fn);
@richardspence
Copy link
Author

It looks like the code emitted from benchmark includes the _read helper from tslib.

This looks to be because donwlevelIteration is turned on in tsc compiler options. That changes the emitted code to enable other scenarios (not tested) - making this slightly an unfair example.

@C-Lodder
Copy link
Collaborator

Thanks @richardspence. I'll try disabling donwlevelIteration and see what the outcome is with the next set of tests

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

2 participants