-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks comparing to Cairo VM (#692)
* Add benches * Fix clippy * Add more cases * Use fibonacci instead of fib * Differenciate expect messages * Separate into groups per program * Add result checks * Fix clippy * Add compile bench * Add linear search * Add linear search bench * Lower time * Fix program * Add linear_search.c * Add builtin * Fix * Fix symbol number * Update benches * Fix bench * Remove comp benchmark * Remove extra dependency --------- Co-authored-by: Edgar <[email protected]> Co-authored-by: Pedro Fontana <[email protected]>
- Loading branch information
1 parent
2bad480
commit 5378651
Showing
3 changed files
with
295 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <assert.h> | ||
#include <stdint.h> | ||
|
||
|
||
typedef struct linear_search_return_values | ||
{ | ||
uint64_t range_check_counter; | ||
uint64_t remaining_gas; | ||
struct { | ||
uint8_t discriminant; | ||
struct { | ||
void *ptr; | ||
uint32_t start; | ||
uint32_t end; | ||
uint32_t cap; | ||
} err; | ||
} result; | ||
} linear_search_return_values_t; | ||
|
||
static void run_bench(linear_search_return_values_t *, uint64_t) | ||
__attribute__((weakref("_mlir_ciface_linear_search::linear_search::main(f4)"))); | ||
|
||
extern uint64_t* cairo_native__set_costs_builtin(uint64_t*); | ||
|
||
int main() | ||
{ | ||
uint64_t BuiltinCosts[7] = {1, 4050, 583, 4085, 491, 230, 604}; | ||
|
||
cairo_native__set_costs_builtin(&BuiltinCosts[0]); | ||
|
||
linear_search_return_values_t return_values; | ||
|
||
run_bench(&return_values, 0xFFFFFFFFFFFFFFFF); | ||
assert((return_values.result.discriminant & 0x1) == 0); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
fn search(array: @Array<felt252>, number: felt252) -> u32 { | ||
let mut index = 0; | ||
|
||
while index < array.len() { | ||
if *array[index] == number { | ||
break; | ||
} | ||
|
||
index += 1; | ||
}; | ||
|
||
return index; | ||
} | ||
|
||
fn init_array(length: u32) -> Array<felt252> { | ||
let mut array = ArrayTrait::new(); | ||
for i in 0..length { | ||
array.append(i.into()); | ||
}; | ||
|
||
return array; | ||
} | ||
|
||
fn main() { | ||
let array = init_array(4001); | ||
|
||
let index = search(@array, 4000); | ||
assert( | ||
index == 4000, | ||
'invalid result' | ||
); | ||
let index = search(@array, 2000); | ||
assert( | ||
index == 2000, | ||
'invalid result' | ||
); | ||
} |