Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active July 7, 2020 15:26
Show Gist options
  • Save shisama/eb1fb567c64b497492c16e98cc8ce631 to your computer and use it in GitHub Desktop.
Save shisama/eb1fb567c64b497492c16e98cc8ce631 to your computer and use it in GitHub Desktop.
Object Performance Test with TypeScript Playground & V8 7.7
const start = performance.now();
interface Member {
name: string;
birthday: Date | null;
url: string | null;
instrument: string | null;
}
const john: Member = {
name: 'John Lennon',
url: 'www.johnlennon.com',
birthday: null,
instrument: null,
};
const paul: Member = {
name: 'Paul McCartney',
birthday: new Date('1942-06-18'),
url: null,
instrument: null,
};
const george: Member = {
name: 'George Harrison',
url: null,
instrument: 'guitar',
birthday: null,
};
const ringo: Member = {
name: 'Ringo Starr',
birthday: null,
url: null,
instrument: null,
};
const beatles = [john, paul, george, ringo];
for (var i = 0; i < 1000 * 1000 * 1000; i++) {
beatles[i & 3].name;
}
const end = performance.now();
console.log(end - start);
// V8 7.7.299.11
// 2875.3000000142492
// 2609.635000000708
// 3082.6799999922514
// Firefox 69
// 45857
const start = performance.now();
interface Member {
name: string;
birthday: Date | null;
url: string | null;
instrument: string | null;
}
const base: Member = {
name: '',
birthday: null,
url: null,
instrument: null
}
const john: Member = {
...base,
name: 'John Lennon',
url: 'www.johnlennon.com',
};
const paul: Member = {
...base,
name: 'Paul McCartney',
birthday: new Date('1942-06-18'),
};
const george: Member = {
...base,
name: 'George Harrison',
instrument: 'guitar',
};
const ringo: Member = {
...base,
name: 'Ringo Starr'
};
const beatles = [john, paul, george, ringo];
for (var i = 0; i < 1000 * 1000 * 1000; i++) {
beatles[i & 3].name;
}
const end = performance.now();
console.log(end - start);
// V8 7.7.299.11
// 1762.7950000169221
// 1421.4800000190735
// 1630.2750000031665
// Firefox 69
// 47372
const start = performance.now();
interface Member {
name: string;
birthday?: Date;
url?: string;
instrument?: string;
}
const john: Member = {
name: 'John Lennon',
url: 'www.johnlennon.com',
};
const paul: Member = {
name: 'Paul McCartney',
birthday: new Date('1942-06-18'),
};
const george: Member = {
name: 'George Harrison',
instrument: 'guitar',
};
const ringo: Member = {
name: 'Ringo Starr'
};
const beatles = [john, paul, george, ringo];
for (var i = 0; i < 1000 * 1000 * 1000; i++) {
beatles[i & 3].name;
}
const end = performance.now();
console.log(end - start);
// V8 7.7.299.11
// 2155.384999990929
// 2514.5250000059605
// 2123.749999998836
// Firefox 69
// 46693
const start = performance.now();
interface Member {
name: string;
birthday: Date | null;
url: string | null;
instrument: string | null;
}
const john: Member = {
name: 'John Lennon',
birthday: null,
url: 'www.johnlennon.com',
instrument: null,
};
const paul: Member = {
name: 'Paul McCartney',
birthday: new Date('1942-06-18'),
url: null,
instrument: null,
};
const george: Member = {
name: 'George Harrison',
birthday: null,
url: null,
instrument: 'guitar',
};
const ringo: Member = {
name: 'Ringo Starr',
birthday: null,
url: null,
instrument: null,
};
const beatles = [john, paul, george, ringo];
for (var i = 0; i < 1000 * 1000 * 1000; i++) {
beatles[i & 3].name;
}
const end = performance.now();
console.log(end - start);
// V8 7.7.299.11
// 1355.4149999981746
// 1644.704999984242
// 1911.8650000018533
// Firefox 69
// 44648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment