Skip to content

Commit

Permalink
Adding bincode.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Aug 2, 2024
1 parent 18eb452 commit 23af1a2
Show file tree
Hide file tree
Showing 19 changed files with 1,674 additions and 37 deletions.
21 changes: 15 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["programs/solana-serialization-benchmark"]
resolver = "2"
members = ["programs/solana-serialization-benchmark"]
resolver = "2"
244 changes: 244 additions & 0 deletions clients/js/bench/bincode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import { generateSigner } from "@metaplex-foundation/umi";
// eslint-disable-next-line import/no-extraneous-dependencies
import test from "ava";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { createBasicBincode, createCollectionBincode, updateBasicBincode, updateCollectionBincode } from '../src';
import { createUmi } from "./_setup";

test('Create:Basic:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
const tx = await createBasicBincode(umi, { address }).sendAndConfirm(umi);

const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});

test('Read:Basic:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
const tx = await createBasicBincode(umi, { address }).sendAndConfirm(umi);

// Then an account was created with the correct data.
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});

test('Update:Basic:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
await createBasicBincode(umi, { address }).sendAndConfirm(umi);
const tx = await updateBasicBincode(umi, { address: address.publicKey }).sendAndConfirm(umi);

const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});

test('Create:Collection:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
const tx = await createCollectionBincode(umi, { address }).sendAndConfirm(umi);

const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});

test('Read:Collection:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
const tx = await createCollectionBincode(umi, { address }).sendAndConfirm(umi);

// Then an account was created with the correct data.
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});

test('Update:Collection:Bincode', async (t) => {
// Given an Umi instance and a new signer.
const umi = await createUmi();
const address = generateSigner(umi);

// When we create a new account.
await createCollectionBincode(umi, { address }).sendAndConfirm(umi);
const tx = await updateCollectionBincode(umi, { address: address.publicKey }).sendAndConfirm(umi);

const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed);
const account = await umi.rpc.getAccount(address.publicKey);
const space = account.exists ? account.data.length : 0;

const cuResult = {
name: `Compute:${t.title}`,
unit: "Compute Units",
value: compute,
}

const spaceResult = {
name: `Space:${t.title}`,
unit: "Bytes",
value: space,
}

// Read the results array from output.json
let output = [];
if (existsSync("../../docs/output.json")) {
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8'));
}

// Push the result to the array
output.push(cuResult);
output.push(spaceResult);
// Write the array to output.json
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2));

t.pass();
});
Loading

0 comments on commit 23af1a2

Please sign in to comment.