Skip to content

Commit d8ee741

Browse files
sui319xgreenx
andcommitted
"flow" op code sanity benchmarks (#1433)
FuelLabs/fuel-core#1386 ``` block target estimation/flow/jmp opcode time: [1.9838 ms 1.9917 ms 2.0001 ms] block target estimation/flow/ji opcode time: [1.6020 ms 1.6119 ms 1.6223 ms] block target estimation/flow/jne opcode time: [2.2373 ms 2.2479 ms 2.2589 ms] block target estimation/flow/jnei opcode time: [2.0990 ms 2.1085 ms 2.1176 ms] block target estimation/flow/jnzi opcode time: [1.9626 ms 1.9776 ms 1.9930 ms] block target estimation/flow/jmpb opcode time: [1.5740 ms 1.5819 ms 1.5904 ms] block target estimation/flow/jmpf opcode time: [1.5385 ms 1.5455 ms 1.5529 ms] block target estimation/flow/jnzb opcode true time: [1.6174 ms 1.6246 ms 1.6323 ms] block target estimation/flow/jnzb opcode false time: [1.6395 ms 1.6482 ms 1.6568 ms] block target estimation/flow/jnzf opcode true time: [1.5932 ms 1.5999 ms 1.6070 ms] block target estimation/flow/jnzf opcode false time: [1.6132 ms 1.6227 ms 1.6333 ms] block target estimation/flow/jne opcode time: [1.7591 ms 1.7703 ms 1.7822 ms] block target estimation/flow/jnei opcode time: [1.5247 ms 1.5340 ms 1.5447 ms] block target estimation/flow/jneb opcode not equal time: [1.6881 ms 1.6961 ms 1.7057 ms] block target estimation/flow/jneb opcode equal time: [1.7255 ms 1.7362 ms 1.7481 ms] block target estimation/flow/jnef opcode not equal time: [1.8018 ms 1.8132 ms 1.8259 ms] block target estimation/flow/jnef opcode equal time: [1.7644 ms 1.7731 ms 1.7823 ms] ``` Not sure how to test `ret_script` or `ret_contract` with an infinite loop 🤷 --------- Co-authored-by: Green Baneling <[email protected]>
1 parent 4b8b84d commit d8ee741

File tree

10 files changed

+230
-17
lines changed

10 files changed

+230
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Description of the upcoming release here.
1010

1111
### Added
1212

13+
- [#1433](https://github.com/FuelLabs/fuel-core/pull/1433): Add "sanity" benchmarks for flow opcodes
14+
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes
1315
- [#1436](https://github.com/FuelLabs/fuel-core/pull/1436): Add a github action to continuously test beta-4.
1416
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes.
1517
- [#1437](https://github.com/FuelLabs/fuel-core/pull/1437): Add some transaction throughput tests for basic transfers.

benches/benches/block_target_gas.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use block_target_gas_set::{
22
alu::run_alu,
3+
contract::run_contract,
34
crypto::run_crypto,
5+
flow::run_flow,
46
};
57
use criterion::{
68
criterion_group,
@@ -175,8 +177,12 @@ fn block_target_gas(c: &mut Criterion) {
175177

176178
run_alu(&mut group);
177179

180+
run_contract(&mut group);
181+
178182
run_crypto(&mut group);
179183

184+
run_flow(&mut group);
185+
180186
group.finish();
181187
}
182188

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::*;
2+
// use crate::utils::arb_dependent_cost_values;
3+
4+
pub fn run_contract(_group: &mut BenchmarkGroup<WallTime>) {
5+
// This breaks the benchmarking
6+
// for i in arb_dependent_cost_values() {
7+
// let id = format!("flow/retd_contract opcode {:?}", i);
8+
// run(
9+
// &id,
10+
// group,
11+
// vec![
12+
// op::movi(0x10, i),
13+
// op::retd(RegId::ONE, 0x10),
14+
// op::jmpb(RegId::ZERO, 0),
15+
// ]
16+
// .to_vec(),
17+
// vec![],
18+
// );
19+
// }
20+
}

benches/benches/block_target_gas_set/crypto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
utils::generate_linear_costs,
2+
utils::arb_dependent_cost_values,
33
*,
44
};
55
use rand::{
@@ -135,7 +135,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
135135
.collect(),
136136
);
137137

138-
for i in generate_linear_costs() {
138+
for i in arb_dependent_cost_values() {
139139
let id = format!("crypto/s256 opcode {:?}", i);
140140
run(
141141
&id,
@@ -152,7 +152,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
152152
)
153153
}
154154

155-
for i in generate_linear_costs() {
155+
for i in arb_dependent_cost_values() {
156156
let id = format!("crypto/k256 opcode {:?}", i);
157157
run(
158158
&id,
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
use crate::*;
2+
3+
// JMP: Jump
4+
// JI: Jump immediate
5+
// JNE: Jump if not equal
6+
// JNEI: Jump if not equal immediate
7+
// JNZI: Jump if not zero immediate
8+
// JMPB: Jump relative backwards
9+
// JMPF: Jump relative forwards
10+
// JNZB: Jump if not zero relative backwards
11+
// JNZF: Jump if not zero relative forwards
12+
// JNEB: Jump if not equal relative backwards
13+
// JNEF: Jump if not equal relative forwards
14+
// RET: Return from context
15+
pub fn run_flow(group: &mut BenchmarkGroup<WallTime>) {
16+
run(
17+
"flow/jmp opcode",
18+
group,
19+
vec![op::movi(0x10, 0), op::jmp(0x10)],
20+
vec![],
21+
);
22+
23+
run(
24+
"flow/ji opcode",
25+
group,
26+
vec![op::ji(0), op::jmpb(RegId::ZERO, 0)],
27+
vec![],
28+
);
29+
30+
run(
31+
"flow/jne opcode",
32+
group,
33+
vec![
34+
op::movi(0x10, 0),
35+
op::jne(RegId::ZERO, RegId::ONE, 0x10),
36+
op::jmpb(RegId::ZERO, 0),
37+
],
38+
vec![],
39+
);
40+
41+
run(
42+
"flow/jnei opcode",
43+
group,
44+
vec![
45+
op::jnei(RegId::ZERO, RegId::ONE, 0),
46+
op::jmpb(RegId::ZERO, 0),
47+
],
48+
vec![],
49+
);
50+
51+
run(
52+
"flow/jnzi opcode",
53+
group,
54+
vec![op::jnzi(RegId::ONE, 0), op::jmpb(RegId::ZERO, 0)],
55+
vec![],
56+
);
57+
58+
run(
59+
"flow/jmpb opcode",
60+
group,
61+
vec![op::noop(), op::jmpb(RegId::ZERO, 0)],
62+
vec![],
63+
);
64+
65+
run(
66+
"flow/jmpf opcode",
67+
group,
68+
vec![op::jmpf(RegId::ZERO, 0), op::jmpb(RegId::ZERO, 0)],
69+
vec![],
70+
);
71+
72+
run(
73+
"flow/jnzb opcode true",
74+
group,
75+
vec![
76+
op::movi(0x10, 1),
77+
op::noop(),
78+
op::jnzb(0x10, RegId::ZERO, 0),
79+
],
80+
vec![],
81+
);
82+
83+
run(
84+
"flow/jnzb opcode false",
85+
group,
86+
vec![
87+
op::movi(0x10, 0),
88+
op::noop(),
89+
op::jnzb(0x10, RegId::ZERO, 0),
90+
op::jmpb(RegId::ZERO, 0),
91+
],
92+
vec![],
93+
);
94+
95+
run(
96+
"flow/jnzf opcode true",
97+
group,
98+
vec![
99+
op::movi(0x10, 1),
100+
op::noop(),
101+
op::jnzf(0x10, RegId::ZERO, 1),
102+
op::ret(RegId::ZERO),
103+
op::jmpb(RegId::ZERO, 1),
104+
],
105+
vec![],
106+
);
107+
108+
run(
109+
"flow/jnzf opcode false",
110+
group,
111+
vec![
112+
op::movi(0x10, 0),
113+
op::noop(),
114+
op::jnzf(0x10, RegId::ZERO, 1),
115+
op::jmpb(RegId::ZERO, 0),
116+
op::noop(),
117+
],
118+
vec![],
119+
);
120+
121+
run(
122+
"flow/jneb opcode not equal",
123+
group,
124+
vec![
125+
op::movi(0x10, 1),
126+
op::movi(0x11, 0),
127+
op::noop(),
128+
op::jneb(0x10, 0x11, RegId::ZERO, 0),
129+
],
130+
vec![],
131+
);
132+
133+
run(
134+
"flow/jneb opcode equal",
135+
group,
136+
vec![
137+
op::movi(0x10, 1),
138+
op::movi(0x11, 1),
139+
op::noop(),
140+
op::jneb(0x10, 0x11, RegId::ZERO, 0),
141+
op::jmpb(RegId::ZERO, 0),
142+
],
143+
vec![],
144+
);
145+
146+
run(
147+
"flow/jnef opcode not equal",
148+
group,
149+
vec![
150+
op::movi(0x10, 1),
151+
op::movi(0x11, 0),
152+
op::noop(),
153+
op::jnef(0x10, 0x11, RegId::ZERO, 1),
154+
op::ret(RegId::ZERO),
155+
op::jmpb(RegId::ZERO, 1),
156+
],
157+
vec![],
158+
);
159+
160+
run(
161+
"flow/jnef opcode equal",
162+
group,
163+
vec![
164+
op::movi(0x10, 1),
165+
op::movi(0x11, 1),
166+
op::noop(),
167+
op::jnef(0x10, 0x11, RegId::ZERO, 1),
168+
op::jmpb(RegId::ZERO, 0),
169+
op::noop(),
170+
],
171+
vec![],
172+
);
173+
174+
// Don't know how to test "returning" op codes
175+
// run(
176+
// "flow/ret_script opcode",
177+
// group,
178+
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(),
179+
// vec![],
180+
// );
181+
//
182+
// run(
183+
// "flow/ret_contract opcode",
184+
// group,
185+
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(),
186+
// vec![],
187+
// );
188+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
pub mod alu;
22

33
pub mod crypto;
4+
5+
pub mod flow;
6+
7+
pub mod contract;

benches/benches/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn make_u256(reg: u8, v: U256) -> Vec<Instruction> {
2727
aloc_bytearray(reg, v.to_be_bytes())
2828
}
2929

30-
pub fn generate_linear_costs() -> Vec<u32> {
30+
pub fn arb_dependent_cost_values() -> Vec<u32> {
3131
let mut linear = vec![1, 10, 100, 1000, 10_000];
3232
let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5))
3333
.take(5)

benches/benches/vm_set/crypto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn run(c: &mut Criterion) {
7373
),
7474
);
7575

76-
let linear = super::utils::generate_linear_costs();
76+
let linear = super::utils::arb_dependent_cost_values();
7777

7878
let mut bench_k256 = c.benchmark_group("k256");
7979
for i in &linear {

benches/benches/vm_set/flow.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use std::iter::successors;
2-
31
use super::run_group_ref;
42

3+
use crate::utils::arb_dependent_cost_values;
54
use criterion::{
65
Criterion,
76
Throughput,
87
};
9-
use fuel_core_benches::*;
8+
use fuel_core_benches::VmBench;
109
use fuel_core_types::fuel_asm::*;
1110
use rand::{
1211
rngs::StdRng,
@@ -16,13 +15,7 @@ use rand::{
1615
pub fn run(c: &mut Criterion) {
1716
let rng = &mut StdRng::seed_from_u64(2322u64);
1817

19-
let mut linear = vec![1, 10, 100, 1000, 10_000];
20-
let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5))
21-
.take(5)
22-
.map(|f| f as u32)
23-
.collect::<Vec<_>>();
24-
l.sort_unstable();
25-
linear.extend(l);
18+
let linear = arb_dependent_cost_values();
2619

2720
run_group_ref(
2821
&mut c.benchmark_group("jmp"),

benches/benches/vm_set/mem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::run_group_ref;
22

3-
use crate::utils::generate_linear_costs;
3+
use crate::utils::arb_dependent_cost_values;
44
use criterion::{
55
Criterion,
66
Throughput,
@@ -54,7 +54,7 @@ pub fn run(c: &mut Criterion) {
5454
]),
5555
);
5656

57-
let linear = generate_linear_costs();
57+
let linear = arb_dependent_cost_values();
5858

5959
run_group_ref(
6060
&mut c.benchmark_group("cfei"),

0 commit comments

Comments
 (0)