-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
/* eslint-disable camelcase */ | ||
|
||
import {bench} from './bench.js'; | ||
|
||
const size = 1_000; | ||
|
||
let userListRecord: Record<string, Record<string, string>> = {}; | ||
let userListMap = new Map<string, Map<string, string>>(); | ||
|
||
function test_make_map() { | ||
userListMap = new Map<string, Map<string, string>>(); | ||
for (let i = size; i; i--) { | ||
const userId = 'user_' + i; | ||
|
||
const user = new Map(); | ||
user.set('user', userId); | ||
user.set('fname', 'ali'); | ||
user.set('lname', 'md'); | ||
user.set('email', '[email protected]'); | ||
user.set('token', '1234abcd'); | ||
|
||
userListMap.set(userId, user); | ||
} | ||
} | ||
|
||
function test_make_obj() { | ||
userListRecord = {}; | ||
for (let i = size; i; i--) { | ||
const userId = 'user_' + i; | ||
userListRecord[userId] = { | ||
user: userId, | ||
fname: 'ali', | ||
lname: 'md', | ||
email: '[email protected]', | ||
token: '1234abcd', | ||
}; | ||
} | ||
} | ||
|
||
function test_access_map() { | ||
if (userListMap.get('user_' + size / 2)!.get('user') !== 'user_' + size / 2) throw new Error('not_match'); | ||
} | ||
|
||
function test_access_obj() { | ||
if (userListRecord['user_' + size / 2]['user'] !== 'user_' + size / 2) throw new Error('not_match'); | ||
} | ||
|
||
bench('test_make_map_1st', test_make_map); | ||
bench('test_make_obj_1st', test_make_obj); | ||
bench('test_access_map_1st', test_access_map); | ||
bench('test_access_obj_1st', test_access_obj); | ||
|
||
bench('test_make_map_2nd', test_make_map); | ||
bench('test_make_obj_2nd', test_make_obj); | ||
bench('test_access_map_2nd', test_access_map); | ||
bench('test_access_obj_2nd', test_access_obj); | ||
|
||
globalThis.document?.body.append(' Done. Check the console.'); |