Skip to content

Instantly share code, notes, and snippets.

@ylt6
Created November 29, 2017 15:08
Show Gist options
  • Save ylt6/8185998d03e80f0d8c0d6fcd91c12662 to your computer and use it in GitHub Desktop.
Save ylt6/8185998d03e80f0d8c0d6fcd91c12662 to your computer and use it in GitHub Desktop.
check_tie_memory_usage
const createTrie = require('autosuggest-trie');
const sizeOf = require('object-sizeof');
// sample data
const locations = [
{
id: 1,
name: 'East Richmond 1234 VIC',
population: 10000
},
{
id: 2,
name: 'East Eagle 1235 VIC',
population: 5000
},
{
id: 3,
name: 'Richmond West 5678 VIC',
population: 4000
},
{
id: 4,
name: 'Cheltenham 3192 Melbourne VIC',
population: 7000
},
{
id: 5,
name: 'Richmond 6776 VIC',
population: 3000
}
];
const trie = createTrie(locations, 'name');
const concatedString = locations
.map(e => e.name)
.reduce((acc, cur) => acc + cur, '');
console.log(`concated string: ${concatedString}`);
console.log(`bytes of string: ${sizeOf(concatedString)}`);
console.log(`bytes of trie: ${sizeOf(trie.trie)}`);
@ylt6
Copy link
Author

ylt6 commented Nov 29, 2017

console output:

concated string: East Richmond 1234 VICEast Eagle 1235 VICRichmond West 5678 VICCheltenham 3192 Melbourne VICRichmond 6776 VIC
bytes of string: 218
bytes of trie: 1556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment