RunKit + npm: mingo

node v10.24.1
endpointsharetweet
var mingo = require("mingo") function makeid(length) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } const arrayToSort = []; for(var i = 0; i < 5000; i++){ arrayToSort.push(makeid(20)); } const mingoSorter1 = new mingo.Aggregator( [ { $sort: { number: 1 } } ], { collation: { locale: 'en', strength: 1 } } ); const mingoSorter2 = new mingo.Aggregator( [ { $sort: { number: 1 } } ] ); console.time('MINGO SORT WITH LOCALE'); const result1 = mingoSorter1.run(arrayToSort); console.timeEnd('MINGO SORT WITH LOCALE'); console.time('MINGO SORT WITHOUT LOCALE'); const result2 = mingoSorter2.run(arrayToSort); console.timeEnd('MINGO SORT WITHOUT LOCALE'); console.time('NATIVE SORT WITHOUT LOCALE'); const result3 = arrayToSort.concat().sort(); console.timeEnd('NATIVE SORT WITHOUT LOCALE'); console.time('NATIVE SORT WITH LOCALE'); const result4 = arrayToSort.concat().sort(function (a,b){ const r = a.localeCompare(b, "en", {sensitivity:'base'}) if (r < 0) return -1 if (r > 0) return 1 return 0 }); console.timeEnd('NATIVE SORT WITH LOCALE');
Created from: https://npm.runkit.com/mingo
Loading…