-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1450 from demergent-labs/stable_b_tree_map_perfor…
…mance_tests Stable b tree map performance tests
- Loading branch information
Showing
30 changed files
with
299 additions
and
163 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
File renamed without changes.
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,16 @@ | ||
{ | ||
"canisters": { | ||
"stable_b_tree_map_instruction_threshold": { | ||
"type": "custom", | ||
"main": "src/index.ts", | ||
"candid": "src/index.did", | ||
"build": "npx azle stable_b_tree_map_instruction_threshold", | ||
"wasm": ".azle/stable_b_tree_map_instruction_threshold/stable_b_tree_map_instruction_threshold.wasm", | ||
"gzip": true, | ||
"declarations": { | ||
"output": "test/dfx_generated/stable_b_tree_map_instruction_threshold", | ||
"node_compatibility": true | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
examples/stable_b_tree_map_instruction_threshold/src/index.did
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,8 @@ | ||
service: () -> { | ||
insertLargeRecord: (nat32) -> (); | ||
insertMediumRecord: (nat32) -> (); | ||
insertSmallRecord: (nat32) -> (); | ||
valuesLargeRecord: (nat32) -> (vec record {id:text; age:nat; signature:vec nat8; internetIdentity:principal; username:text; mediumRecord:record {id:text; age:nat; internetIdentity:principal; username:text}; friends:vec text}) query; | ||
valuesMediumRecord: (nat32) -> (vec record {id:text; age:nat; internetIdentity:principal; username:text}) query; | ||
valuesSmallRecord: (nat32) -> (vec record {id:principal}) query; | ||
} |
111 changes: 111 additions & 0 deletions
111
examples/stable_b_tree_map_instruction_threshold/src/index.ts
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,111 @@ | ||
import { | ||
blob, | ||
Canister, | ||
nat, | ||
nat32, | ||
Principal, | ||
query, | ||
Record, | ||
StableBTreeMap, | ||
stableJson, | ||
text, | ||
update, | ||
Vec, | ||
Void | ||
} from 'azle'; | ||
import { v4 } from 'uuid'; | ||
|
||
const SmallRecord = Record({ | ||
id: Principal | ||
}); | ||
type SmallRecord = typeof SmallRecord.tsType; | ||
|
||
let smallRecordMap = StableBTreeMap<string, SmallRecord>( | ||
stableJson, | ||
stableJson, | ||
0 | ||
); | ||
|
||
const MediumRecord = Record({ | ||
id: text, | ||
username: text, | ||
age: nat, | ||
internetIdentity: Principal | ||
}); | ||
type MediumRecord = typeof MediumRecord.tsType; | ||
|
||
let mediumRecordMap = StableBTreeMap<string, MediumRecord>( | ||
stableJson, | ||
stableJson, | ||
1 | ||
); | ||
|
||
const LargeRecord = Record({ | ||
id: text, | ||
username: text, | ||
age: nat, | ||
internetIdentity: Principal, | ||
signature: blob, | ||
friends: Vec(text), | ||
mediumRecord: MediumRecord | ||
}); | ||
type LargeRecord = typeof LargeRecord.tsType; | ||
|
||
let largeRecordMap = StableBTreeMap<string, LargeRecord>( | ||
stableJson, | ||
stableJson, | ||
2 | ||
); | ||
|
||
export default Canister({ | ||
insertSmallRecord: update([nat32], Void, (numToInsert) => { | ||
for (let i = 0; i < numToInsert; i++) { | ||
const id = v4(); | ||
|
||
smallRecordMap.insert(id, { | ||
id: Principal.fromText('aaaaa-aa') | ||
}); | ||
} | ||
}), | ||
valuesSmallRecord: query([nat32], Vec(SmallRecord), (numToReturn) => { | ||
return smallRecordMap.values(0, numToReturn); | ||
}), | ||
insertMediumRecord: update([nat32], Void, (numToInsert) => { | ||
for (let i = 0; i < numToInsert; i++) { | ||
const id = v4(); | ||
|
||
mediumRecordMap.insert(id, { | ||
id, | ||
username: `lastmjs${i}`, | ||
age: BigInt(i), | ||
internetIdentity: Principal.fromText('aaaaa-aa') | ||
}); | ||
} | ||
}), | ||
valuesMediumRecord: query([nat32], Vec(MediumRecord), (numToReturn) => { | ||
return mediumRecordMap.values(0, numToReturn); | ||
}), | ||
insertLargeRecord: update([nat32], Void, (numToInsert) => { | ||
for (let i = 0; i < numToInsert; i++) { | ||
const id = v4(); | ||
|
||
largeRecordMap.insert(id, { | ||
id, | ||
username: `lastmjs${i}`, | ||
age: BigInt(i), | ||
internetIdentity: Principal.fromText('aaaaa-aa'), | ||
signature: Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | ||
friends: [v4(), v4(), v4(), v4()], | ||
mediumRecord: { | ||
id, | ||
username: `lastmjs${i}`, | ||
age: BigInt(i), | ||
internetIdentity: Principal.fromText('aaaaa-aa') | ||
} | ||
}); | ||
} | ||
}), | ||
valuesLargeRecord: query([nat32], Vec(LargeRecord), (numToReturn) => { | ||
return largeRecordMap.values(0, numToReturn); | ||
}) | ||
}); |
20 changes: 20 additions & 0 deletions
20
examples/stable_b_tree_map_instruction_threshold/test/pretest.ts
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,20 @@ | ||
import { execSync } from 'child_process'; | ||
|
||
async function pretest() { | ||
execSync( | ||
`dfx canister uninstall-code stable_b_tree_map_instruction_threshold || true`, | ||
{ | ||
stdio: 'inherit' | ||
} | ||
); | ||
|
||
execSync(`dfx deploy stable_b_tree_map_instruction_threshold`, { | ||
stdio: 'inherit' | ||
}); | ||
|
||
execSync(`dfx generate stable_b_tree_map_instruction_threshold`, { | ||
stdio: 'inherit' | ||
}); | ||
} | ||
|
||
pretest(); |
14 changes: 14 additions & 0 deletions
14
examples/stable_b_tree_map_instruction_threshold/test/test.ts
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,14 @@ | ||
import { getCanisterId, runTests } from 'azle/test'; | ||
import { createActor } from './dfx_generated/stable_b_tree_map_instruction_threshold'; | ||
import { getTests } from './tests'; | ||
|
||
const stableBTreeMapInstructionThresholdCanister = createActor( | ||
getCanisterId('stable_b_tree_map_instruction_threshold'), | ||
{ | ||
agentOptions: { | ||
host: 'http://127.0.0.1:8000' | ||
} | ||
} | ||
); | ||
|
||
runTests(getTests(stableBTreeMapInstructionThresholdCanister)); |
61 changes: 61 additions & 0 deletions
61
examples/stable_b_tree_map_instruction_threshold/test/tests.ts
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,61 @@ | ||
import { ActorSubclass } from '@dfinity/agent'; | ||
import { Test } from 'azle/test'; | ||
import { _SERVICE } from './dfx_generated/stable_b_tree_map_instruction_threshold/stable_b_tree_map_instruction_threshold.did'; | ||
|
||
export function getTests( | ||
stableBTreeMapInstructionThresholdCanister: ActorSubclass<_SERVICE> | ||
): Test[] { | ||
return [ | ||
{ | ||
name: 'test SmallRecord', | ||
test: async () => { | ||
await stableBTreeMapInstructionThresholdCanister.insertSmallRecord( | ||
10_000 | ||
); | ||
|
||
const result = | ||
await stableBTreeMapInstructionThresholdCanister.valuesSmallRecord( | ||
6_000 | ||
); | ||
|
||
return { | ||
Ok: result.length === 6_000 | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'test MediumRecord', | ||
test: async () => { | ||
await stableBTreeMapInstructionThresholdCanister.insertMediumRecord( | ||
5_000 | ||
); | ||
|
||
const result = | ||
await stableBTreeMapInstructionThresholdCanister.valuesMediumRecord( | ||
1_000 | ||
); | ||
|
||
return { | ||
Ok: result.length === 1_000 | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'test LargeRecord', | ||
test: async () => { | ||
await stableBTreeMapInstructionThresholdCanister.insertLargeRecord( | ||
2_000 | ||
); | ||
|
||
const result = | ||
await stableBTreeMapInstructionThresholdCanister.valuesLargeRecord( | ||
500 | ||
); | ||
|
||
return { | ||
Ok: result.length === 500 | ||
}; | ||
} | ||
} | ||
]; | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.