Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/js sdk improvement #69

Merged
merged 20 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions js/benchmarks/nft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require("dotenv").config();
import { Connection, PublicKey } from "@solana/web3.js";
import { retrieveNftOwner, retrieveNftOwnerV2 } from "../src/nft";
import { mean, median } from "mathjs";

const benchmark = async () => {
const connection = new Connection(process.env.RPC_URL!);

const nameAccounts = [
new PublicKey("5RDpkiLAvYh5StaFbFdvkMnezQCFAN2vGyhVEeQHMTf"),
new PublicKey("AVdePc1a3CXg56GzHLz8jxB5MxV4Fh3iKU7z7xbgDTEY"),
new PublicKey("AQzjja886kuZpY3Bm8ataXDvJemwrwV91dHypZ45vaei"),
new PublicKey("2nD7dijypykUCBxzLmPc21trzAZd2CWoQurWBRt5qg3D"),
new PublicKey("Fwyp251aoe5LEis4WNjAvs9D7z4bSZSi4inangghgwf3"),
new PublicKey("CT3kcSzzkaay8UpYJmYvGvXJLQPziFqJCgyetr7GhSpB"),
new PublicKey("797fVNoYuyMcLf3d6oztSCAJSrevJ4dWrGy9B9xKWujy"),
new PublicKey("F9ESKiA79dsHxhC3h7iLGTnVU5iPcaCKWaRDmTm9tiEa"),
];

const results: any[] = [];
const times1: number[] = [];
const times2: number[] = [];

for (const nameAccount of nameAccounts) {
const accountBase58 = nameAccount.toBase58();

console.time(`retrieveNftOwner-${accountBase58}`);
const start1 = performance.now();
const owner1 = await retrieveNftOwner(connection, nameAccount);
const end1 = performance.now();
console.timeEnd(`retrieveNftOwner-${accountBase58}`);
const time1 = end1 - start1;
times1.push(time1);

console.time(`retrieveNftOwnerV2-${accountBase58}`);
const start2 = performance.now();
const owner2 = await retrieveNftOwnerV2(connection, nameAccount);
const end2 = performance.now();
console.timeEnd(`retrieveNftOwnerV2-${accountBase58}`);
const time2 = end2 - start2;
times2.push(time2);

results.push({
Account: accountBase58,
Owner1: owner1?.toBase58() || "N/A",
Time1: `${time1.toFixed(2)} ms`,
Owner2: owner2?.toBase58() || "N/A",
Time2: `${time2.toFixed(2)} ms`,
});
}

console.table(results);

const avgTime1 = mean(times1);
const medianTime1 = median(times1);
const avgTime2 = mean(times2);
const medianTime2 = median(times2);

console.table([
{
Metric: "Average Time (retrieveNftOwner)",
Value: `${avgTime1.toFixed(2)} ms`,
},
{
Metric: "Median Time (retrieveNftOwner)",
Value: `${medianTime1.toFixed(2)} ms`,
},
{
Metric: "Average Time (retrieveNftOwnerV2)",
Value: `${avgTime2.toFixed(2)} ms`,
},
{
Metric: "Median Time (retrieveNftOwnerV2)",
Value: `${medianTime2.toFixed(2)} ms`,
},
]);
};

benchmark().catch(console.error);
Loading
Loading