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

performance: improved perfs by circa 50% #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Cadienvan
Copy link

Moving from the regexp approach to a loop based one.

Performances improved by 50% in my benchmark. I did that using the following code:

const mjn = require("./dist/main.js");
const { performance } = require("perf_hooks");

const start = performance.now();

const SimpleObj = {
  id: 29002,
  name: {
    first: "John",
    last: "Doe"
  },
  birth: {
    year: 1950,
    month: "Jan",
    day: 29
  },
  contacts: {
    email: {
      work: "foo@johndoefoo.foo",
      home: null
    }
  },
  children_ids: [29182, 29381, 29383]
};

const operationsToDo = [
  () => mjn(SimpleObj, "name.first"),
  () => mjn(SimpleObj, "name.last"),
  () => mjn(SimpleObj, "birth.year"),
  () => mjn(SimpleObj, "birth.month"),
  () => mjn(SimpleObj, "birth.day"),
  () => mjn(SimpleObj, "contacts.email.work"),
  () => mjn(SimpleObj, "contacts.email.home"),
  () => mjn(SimpleObj, "children_ids[0]"),
  () => mjn(SimpleObj, "children_ids[1]"),
  () => mjn(SimpleObj, "children_ids[2]")
];

for (let i = 0; i < 100000; i++) {
  operationsToDo.forEach(operation => operation());
}

const end = performance.now();

console.log("Time taken: ", end - start);

And time taken went from 680-690ms to 320-340ms.

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

Successfully merging this pull request may close these issues.

None yet

1 participant