Skip to content

Commit

Permalink
Fixes for old benchmark code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Apr 29, 2024
1 parent d12cea7 commit ab3b207
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class CVMBenchmark {

// Move some USD to Hero
Context ctx=Context.createFake(STATE, Init.INIT_ADDRESS);
ctx=ctx.eval(Reader.read("(do (import currency.USD :as usd) (fun/transfer usd "+HERO+" 100000000))"));
ctx=ctx.eval(Reader.read("(do (import convex.fungible :as fun) (import currency.CFUSD :as usd) (fun/transfer usd "+HERO+" 0))"));
if (ctx.isError()) throw new Error("Problem moving USD: "+ctx.getError().toString());
STATE=ctx.getState();

// Get a USD MARKET
ctx=Context.createFake(STATE, HERO);
ctx=ctx.eval(Reader.read("(do (import currency.USD :as usd) "
ctx=ctx.eval(Reader.read("(do (import currency.CFUSD :as usd) "
+ "(import torus.exchange :as torus) "
+ "(def market (torus/create-market usd)))"));
if (ctx.isError()) throw new Error("Problem getting market: "+ctx.getError().toString());
Expand All @@ -66,7 +66,7 @@ public void smallTransfer() {
Address addr=HERO;
ATransaction trans=Transfer.create(addr,1, Benchmarks.VILLAIN, 1000);
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

@Benchmark
Expand All @@ -75,7 +75,7 @@ public void simpleCalculationStatic() {
Address addr=HERO;
ATransaction trans=Invoke.create(addr,1, convex.core.lang.ops.Invoke.create(Constant.create(Core.PLUS),Constant.of(1L),Constant.of(2L)));
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

@Benchmark
Expand All @@ -84,7 +84,7 @@ public void simpleCalculationDynamic() {
Address addr=HERO;
ATransaction trans=Invoke.create(addr,1, convex.core.lang.ops.Invoke.create(Lookup.create("+"),Constant.of(1L),Constant.of(2L)));
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

@Benchmark
Expand All @@ -111,7 +111,7 @@ public void defInEnvironment() {
Address addr=HERO;
ATransaction trans=Invoke.create(addr,1, convex.core.lang.ops.Def.create("a", Constant.of(13L)));
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

@Benchmark
Expand All @@ -129,7 +129,7 @@ public void deployToken() {
Address addr=HERO;
ATransaction trans=Invoke.create(addr,1, Reader.read("(do (import convex.fungible :as fun) (deploy (fun/build-token {:supply 1000000})))"));
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

static final ATransaction buyTrade=Invoke.create(HERO,1, Reader.read("(torus/buy-tokens usd 10)"));
Expand All @@ -148,7 +148,7 @@ public void contractCall() {
Address addr=HERO;
ATransaction trans=Call.create(addr,1L, Init.REGISTRY_ADDRESS, Symbols.REGISTER, Vectors.of(Maps.of(Keywords.NAME,Strings.create("Bob"))));
ResultContext ctx=s.applyTransaction(trans);
ctx.context.getValue();
ctx.context.getResult();
}

public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public class LatencyBenchmark {

@Benchmark
public void roundTripTransaction() throws TimeoutException, IOException {
client.transactSync(Invoke.create(Benchmarks.HERO,-1, Constant.of(1L)));
client.transactSync(Invoke.create(Benchmarks.HERO,0, Constant.of(1L)));
// System.out.println(server.getBroadcastCount());
}

@Benchmark
public void roundTripTwoTransactions() throws TimeoutException, IOException, InterruptedException, ExecutionException {
Future<Result> r1=client.transact(Invoke.create(HERO,-1, Constant.of(1L)));
Future<Result> r2=client2.transact(Invoke.create(VILLAIN,-1, Constant.of(1L)));
Future<Result> r1=client.transact(Invoke.create(HERO,0, Constant.of(1L)));
Future<Result> r2=client2.transact(Invoke.create(VILLAIN,0, Constant.of(1L)));
r1.get(1000,TimeUnit.MILLISECONDS);
r2.get(1000,TimeUnit.MILLISECONDS);
}
Expand All @@ -97,7 +97,7 @@ public void roundTrip1000Transactions() throws TimeoutException, IOException, In
private void doTransactions(int n) throws IOException, InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<Result>[] rs=new CompletableFuture[n];
for (int i=0; i<n; i++) {
CompletableFuture<Result> f=client.transact(Invoke.create(HERO,-1, Constant.of(i)));
CompletableFuture<Result> f=client.transact(Invoke.create(HERO,0, Constant.of(i)));
rs[i]=f;
}
CompletableFuture.allOf(rs).get(1000,TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class LocalPeerBenchmark {

SERVER=servers.get(0);
PEER_CLIENT=Convex.connect(SERVER, Init.GENESIS_ADDRESS, PEER_KP);
String cmd="(let [ha (create-account "+HERO_KEY+")] (transfer ha 1000000000000000) ha)";
String cmd="(let [ha (create-account "+HERO_KEY+")] (transfer ha 1000000) ha)";
Result hr=PEER_CLIENT.transactSync(cmd);
if (hr.isError()) {
throw new Error("Transaction Failed: "+hr.toString());
Expand Down

0 comments on commit ab3b207

Please sign in to comment.