HowProgrammingWorks / Benchmark

Performance testing for different techniques
https://www.youtube.com/TimurShemsedinov
MIT License
17 stars 15 forks source link

Adding test of different methods of creating objects in JS. #6

Closed ALEXKIRNAS closed 7 years ago

ALEXKIRNAS commented 7 years ago

Adding test of different methods of creating objects in JS. Compare speed of creating + using objects. Creating objects using:

In my realization time of runs: prototypes <= classes < closures <= mixing

aqrln commented 7 years ago

@ALEXKIRNAS thanks for your contribution! Feel free to ping me if you have any questions or you'll need help with fixing any of the issues and nits mentioned above or the ones that may be found during the further review.

ALEXKIRNAS commented 7 years ago

@aqrln I already fixed problems, that you described. And I have a question. I want to test a speed of creating object in file "c-obj-create.js" when I run it like "node c-obj-create.js". But I wan`t to see this test when I use this file as module in other programs. Have can I do this?

aqrln commented 7 years ago

@ALEXKIRNAS probably the easiest way to do it is

if (module.parent === null) {
  // this code will only be executed when the file is run as a script,
  // not when it is required by other modules
}
aqrln commented 7 years ago

I already fixed problems, that you described.

Not all of them. The .eslintrc.yml file is still present in the PR and I still ask you to rebase your branch on top of master :)

ALEXKIRNAS commented 7 years ago

@aqrln Fixed. And another question. How I can add name to functions? Now my version looks like this: creaters.mixinCreate = function mixinCreate() { // Here my code };

aqrln commented 7 years ago

@ALEXKIRNAS well, that's the only way. V8 is pretty good at constructing function names itself for stacktraces, but fn.name works with named functions only.

aqrln commented 7 years ago

I'd prefer the benchmarking framework to not rely upon fn.name though.

ALEXKIRNAS commented 7 years ago

@aqrln It's easy to fix up. We can add new argument (array of function`s names) when we call function. Then inside benchmark.do function we choose name for displaying in next order:

  1. If to function call added array of names we choose from it.
  2. If function called without array of names we trying to get name from fn.name
  3. If point 1 and 2 is failed then we naming function some default way, like 'Anonymius'. I can modify benchmark file in this way.
aqrln commented 7 years ago

@ALEXKIRNAS PRs are welcome, go for it :)

ALEXKIRNAS commented 7 years ago

@aqrln Done.

aqrln commented 7 years ago

@ALEXKIRNAS it must be a different PR.

ALEXKIRNAS commented 7 years ago

@aqrln You mean create new branch and make new PR?

aqrln commented 7 years ago

Yep. This PR is about object creation benchmarking, not about the benchmarking tools.

ALEXKIRNAS commented 7 years ago

@aqrln Okay. I delete it from this PR and add new PR.

ALEXKIRNAS commented 7 years ago

@aqrln Fixed.