Merge pull request #98 from blockworks-foundation/optimize_create_n_users.bench
optimize create n users.bench
This commit is contained in:
commit
c4df81e94a
|
@ -3,5 +3,6 @@ node_modules
|
|||
bench/metrics.csv
|
||||
*.pem*
|
||||
*.pks*
|
||||
*out.json*
|
||||
.env
|
||||
test-ledger
|
||||
|
|
|
@ -69,13 +69,15 @@ impl BenchHelper {
|
|||
funded_payer: &Keypair,
|
||||
blockhash: Hash,
|
||||
) -> Vec<Transaction> {
|
||||
(0..num_of_txs)
|
||||
.map(|_| {
|
||||
let random_bytes: Vec<u8> = Alphanumeric
|
||||
.sample_iter(rand::thread_rng())
|
||||
.take(10)
|
||||
.collect();
|
||||
|
||||
(0..num_of_txs)
|
||||
.map(|_| Self::create_memo_tx(&random_bytes, funded_payer, blockhash))
|
||||
Self::create_memo_tx(&random_bytes, funded_payer, blockhash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
|
||||
import * as fs from 'fs';
|
||||
import { Connection, Keypair } from '@solana/web3.js';
|
||||
import * as splToken from "@solana/spl-token";
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
// number of users
|
||||
|
@ -10,13 +10,13 @@ const url = process.argv.length > 3 ? process.argv[3] : "http://0.0.0.0:8899";
|
|||
// outfile
|
||||
const outFile = process.argv.length > 4 ? process.argv[4] : "out.json";
|
||||
|
||||
console.log("creating " + nbUsers + " Users on " + url + " out file " + outFile);
|
||||
function delay(ms: number) {
|
||||
return new Promise( resolve => setTimeout(resolve, ms) );
|
||||
}
|
||||
export async function main() {
|
||||
(async function main() {
|
||||
console.log("Creating " + nbUsers + " Users on " + url + " out file " + outFile);
|
||||
console.time('Time taken');
|
||||
|
||||
const connection = new Connection(url, 'confirmed');
|
||||
let authority = Keypair.fromSecretKey(
|
||||
|
||||
const authority = Keypair.fromSecretKey(
|
||||
Uint8Array.from(
|
||||
JSON.parse(
|
||||
process.env.KEYPAIR ||
|
||||
|
@ -25,29 +25,26 @@ export async function main() {
|
|||
),
|
||||
);
|
||||
|
||||
let userKps = [...Array(nbUsers)].map(_x => Keypair.generate())
|
||||
let mint = await splToken.createMint(
|
||||
const userKps = Array(nbUsers).fill(0).map(() => Keypair.generate());
|
||||
|
||||
const mint = await splToken.createMint(
|
||||
connection,
|
||||
authority,
|
||||
authority.publicKey,
|
||||
null,
|
||||
6,
|
||||
);
|
||||
let accounts : PublicKey[] = [];
|
||||
for (const user of userKps) {
|
||||
console.log("account created");
|
||||
let account = await splToken.createAccount(
|
||||
|
||||
const accounts = await Promise.all(userKps.map(async user => {
|
||||
const account = await splToken.createAccount(
|
||||
connection,
|
||||
authority,
|
||||
mint,
|
||||
user.publicKey,
|
||||
)
|
||||
accounts.push(account)
|
||||
await delay(100)
|
||||
};
|
||||
);
|
||||
|
||||
console.log("Account created");
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log("account minted");
|
||||
await splToken.mintTo(
|
||||
connection,
|
||||
authority,
|
||||
|
@ -56,16 +53,18 @@ export async function main() {
|
|||
authority,
|
||||
1_000_000_000_000,
|
||||
)
|
||||
await delay(100)
|
||||
};
|
||||
|
||||
const users = userKps.map(x => {
|
||||
const info = {
|
||||
console.log("Account minted");
|
||||
|
||||
return account;
|
||||
}));
|
||||
|
||||
console.timeLog('Time taken');
|
||||
|
||||
const users = userKps.map(x => ({
|
||||
'publicKey': x.publicKey.toBase58(),
|
||||
'secretKey': Array.from(x.secretKey)
|
||||
};
|
||||
return info;
|
||||
});
|
||||
}));
|
||||
|
||||
const data = {
|
||||
'users': users,
|
||||
|
@ -75,11 +74,6 @@ export async function main() {
|
|||
};
|
||||
|
||||
console.log('created ' + nbUsers + ' Users and minted 10^12 tokens for mint ' + mint);
|
||||
fs.writeFileSync(outFile, JSON.stringify(data));
|
||||
}
|
||||
|
||||
main().then(x => {
|
||||
console.log('finished sucessfully')
|
||||
}).catch(e => {
|
||||
console.log('caught an error : ' + e)
|
||||
})
|
||||
fs.writeFileSync(outFile, JSON.stringify(data));
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue