Skip to content

Lightprotocol/cu-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CU Library Benchmarks

Benchmark results for Solana runtime operations.

Table of Contents

1. Baseline

2. Collections

3. Conversions

4. Math

5. Option

6. Partial Eq

7. Pinocchio Crates

8. Serialization

9. Solana Crates

Definitions

  • CU Consumed: Total compute units consumed by the profiled function
  • CU Adjusted: Actual operation cost with baseline profiling overhead subtracted (CU Consumed - Baseline CU)
  • Baseline CU: CU consumed by an empty profiled function (#[profile] macro overhead)

1. Baseline

1.1 Lib

Function CU Consumed CU Adjusted
baseline_empty_function 6 N/A

2. Collections

2.1 Array

Function CU Consumed CU Adjusted
new 10 4
with_capacity_10 8 2
with_capacity_100 27 21
assign_u8 9 3
assign_u64 16 10
assign_pubkey 108 102
assign_10_u8 9 3
assign_10_u64 16 10
assign_10_pubkey 108 102
array_u8_32_index 9 3
array_u8_32_get 6 0
array_u8_32_get_ok_or 6 0
array_u8_32_if_let_get 9 3
array_u64_10_index 9 3
array_u64_10_get 6 0
array_u64_10_get_ok_or 6 0
array_u64_10_if_let_get 9 3

2.2 Arrayvec

Function CU Consumed CU Adjusted
u8_new 7 1
push_pubkey 29 23
push_u64 22 16
push_u8 20 14
u8_with_capacity_10 7 1
u8_with_capacity_100 7 1
push_10_u8 10 4
push_10_u64 17 11
push_10_pubkey 87 81
get_first_pubkey 6 0
get_10th_pubkey 6 0
find_pubkey_1_iters 18 12
find_pubkey_10_iters 38 32
position_pubkey_1_iters 42 36
position_pubkey_10_iters 87 81
update_index 14 8
update_get_mut 15 9
update_iter_mut_find 25 19

2.3 Heapless

Function CU Consumed CU Adjusted
u8_new 6 0
u8_with_capacity_10 6 0
u8_with_capacity_100 6 0
push_u8 8 2
push_u64 8 2
push_pubkey 15 9
push_10_u8 10 4
push_10_u64 17 11
push_10_pubkey 88 82
get_first_pubkey 6 0
get_10th_pubkey 6 0
find_pubkey_1_iters 18 12
find_pubkey_10_iters 38 32
position_pubkey_1_iters 42 36
position_pubkey_10_iters 87 81
update_index 15 9
update_get_mut 15 9
update_iter_mut_find 24 18

2.4 Smallvec

Function CU Consumed CU Adjusted
u8_new 6 0
u8_with_capacity_10 6 0
u8_with_capacity_128 6 0
push_u8 25 19
push_u64 27 21
push_pubkey 33 27
push_10_u8 10 4
push_10_u64 17 11
push_10_pubkey 87 81
get_first_pubkey 6 0
get_10th_pubkey 6 0
find_pubkey_1_iters 21 15
find_pubkey_10_iters 38 32
position_pubkey_1_iters 44 38
position_pubkey_10_iters 87 81
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 27 21

2.5 Tinyvec

Function CU Consumed CU Adjusted
u8_new 6 0
u8_with_capacity_10 6 0
u8_with_capacity_100 6 0
push_u8 8 2
push_u64 8 2
push_pubkey 15 9
push_10_u8 10 4
push_10_u64 17 11
push_10_pubkey 87 81
get_first_pubkey 6 0
get_10th_pubkey 6 0
find_pubkey_1_iters 18 12
find_pubkey_10_iters 38 32
position_pubkey_1_iters 42 36
position_pubkey_10_iters 87 81
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 25 19

2.6 Tinyvec Heap

Function CU Consumed CU Adjusted
u8_new 6 0
push_u8 8 2
push_u64 8 2
push_pubkey 15 9
push_10_u8 159 153
push_10_u64 151 145
push_10_pubkey 256 250

2.7 Vec

Function CU Consumed CU Adjusted
u8_new 9 3
u8_with_capacity_10 113 107
u8_with_capacity_100 113 107
push_u8 73 67
push_u64 78 72
push_pubkey 84 78
push_10_u8 200 194
push_10_u64 308 302
push_10_pubkey 376 370
push_u8_with_capacity 120 114
push_u64_with_capacity 120 114
push_pubkey_with_capacity 127 121
push_10_u8_with_capacity 154 148
push_10_u64_with_capacity 150 144
push_10_pubkey_with_capacity 219 213
vec_u8_32_index 9 3
vec_u8_32_get 8 2
vec_u8_32_get_ok_or 8 2
vec_u8_32_if_let_get 9 3
vec_u64_10_index 9 3
vec_u64_10_get 8 2
vec_u64_10_get_ok_or 8 2
vec_u64_10_if_let_get 9 3

3. Conversions

3.1 Cast U16

Function CU Consumed CU Adjusted
u16_as_u8 7 1
u16_as_u32 7 1
u16_as_u64 7 1
u16_as_usize 7 1

3.2 Cast U32

Function CU Consumed CU Adjusted
u32_as_u8 7 1
u32_as_u16 7 1
u32_as_u64 7 1
u32_as_usize 7 1

3.3 Cast U64

Function CU Consumed CU Adjusted
u64_as_u8 7 1
u64_as_u16 7 1
u64_as_u32 7 1
u64_as_usize 7 1

3.4 Cast U8

Function CU Consumed CU Adjusted
u8_as_u16 7 1
u8_as_u32 7 1
u8_as_u64 7 1
u8_as_usize 7 1

3.5 From Usize

Function CU Consumed CU Adjusted
try_into_usize_to_u64_unwrap 7 1
try_into_usize_to_u64_map_err 6 0

3.6 Slice To Array

Function CU Consumed CU Adjusted
try_into_slice_to_array_32_unwrap 14 8
try_into_slice_to_array_32_map_err 6 0

3.7 To Usize

Function CU Consumed CU Adjusted
try_into_u64_to_usize_unwrap 7 1
try_into_u64_to_usize_map_err 6 0
try_into_u32_to_usize_unwrap 7 1
try_into_u32_to_usize_map_err 6 0
try_into_u16_to_usize_unwrap 7 1
try_into_u16_to_usize_map_err 6 0
try_into_u8_to_usize_unwrap 7 1
try_into_u8_to_usize_map_err 6 0

4. Math

4.1 Checked Math

Function CU Consumed CU Adjusted
add_u8 7 1
add_u16 7 1
add_u32 8 2
add_u64 8 2
add_u128 10 4
sub_u8 7 1
sub_u16 7 1
sub_u32 8 2
sub_u64 8 2
sub_u128 10 4
mul_u8 7 1
mul_u16 7 1
mul_u32 8 2
mul_u64 8 2
mul_u128 10 4
div_u8 7 1
div_u16 7 1
div_u32 8 2
div_u64 8 2
div_u128 10 4

4.2 Saturating Math

Function CU Consumed CU Adjusted
add_u8 7 1
add_u16 7 1
add_u32 7 1
add_u64 7 1
add_u128 8 2
sub_u8 7 1
sub_u16 7 1
sub_u32 7 1
sub_u64 7 1
sub_u128 8 2
mul_u8 7 1
mul_u16 7 1
mul_u32 7 1
mul_u64 7 1
mul_u128 8 2

4.3 Std Math

Function CU Consumed CU Adjusted
add_u8 6 0
add_u16 6 0
add_u32 6 0
add_u64 6 0
add_u128 6 0
sub_u8 6 0
sub_u16 6 0
sub_u32 6 0
sub_u64 6 0
sub_u128 6 0
mul_u8 6 0
mul_u16 6 0
mul_u32 6 0
mul_u64 6 0
mul_u128 6 0
div_u8 6 0
div_u16 6 0
div_u32 6 0
div_u64 6 0
div_u128 6 0
add_assign_u8 7 1
add_assign_u16 7 1
add_assign_u32 7 1
add_assign_u64 7 1
add_assign_u128 9 3
sub_assign_u8 7 1
sub_assign_u16 7 1
sub_assign_u32 7 1
sub_assign_u64 7 1
sub_assign_u128 9 3

5. Option

5.1 Option Checked Add

Function CU Consumed CU Adjusted
checked_add_u8_unwrap 7 1
checked_add_u8_ok_or 6 0
checked_add_u8_ok_or_else 6 0
checked_add_u8_unwrap_or_default 7 1
checked_add_u8_unwrap_or 7 1

5.2 Option If Let

Function CU Consumed CU Adjusted
if_let_some_u8 6 0
if_let_some_array 14 8
if_let_some_pubkey 14 8
if_let_some_array_ref 6 0

5.3 Option Pubkey Ref

Function CU Consumed CU Adjusted
pubkey_ref_map_deref 6 0
pubkey_as_ref_map_convert 6 0

5.4 Option Slice Get

Function CU Consumed CU Adjusted
slice_get_array_unwrap 14 8
slice_get_array_ok_or 6 0
slice_get_array_ok_or_else 6 0
slice_get_array_unwrap_or_default 14 8
slice_get_array_unwrap_or 14 8

6. Partial Eq

6.1 Partial Eq Arrays

Function CU Consumed CU Adjusted
array_u8_32_ref 7 1
array_u8_32 6 0
array_u16_32 7 1
array_u32_32 7 1
array_u64_32 7 1

6.2 Partial Eq Neq

Function CU Consumed CU Adjusted
u8_neq 9 3
u16_neq 9 3
u32_neq 10 4
u64_neq 10 4
u128_neq 13 7
array_u8_32_neq_ref 23 17
array_u8_32_neq 20 14
array_u8_32_neq_deref 23 17
array_u16_32_neq 33 27
array_u32_32_neq 34 28
array_u64_32_neq 34 28

6.3 Partial Eq Primitives

Function CU Consumed CU Adjusted
u8 7 1
u16 7 1
u32 7 1
u64 7 1
u128 7 1

7. Pinocchio Crates

7.1 Account Info

Function CU Consumed CU Adjusted
key 9 3
owner 9 3
is_signer 12 6
is_writable 11 5
executable 12 6
data_len 9 3
lamports 9 3
data_is_empty 12 6
is_owned_by 21 15
assign 15 9
is_borrowed 12 6
borrow_lamports_unchecked 9 3
borrow_mut_lamports_unchecked 9 3
borrow_data_unchecked 8 2
borrow_mut_data_unchecked 8 2
try_borrow_lamports 15 9
try_borrow_mut_lamports 10 4
can_borrow_lamports 8 2
can_borrow_mut_lamports 8 2
try_borrow_data 14 8
try_borrow_mut_data 11 5
can_borrow_data 8 2
can_borrow_mut_data 8 2
realloc 16 10

7.2 Account Meta

Function CU Consumed CU Adjusted
account_meta_array_10 6 0
account_info_array_10_ref 6 0
account_info_array_10_clone 6 0
account_info_array_10_move 6 0
arrayvec_push_account_meta_10 179 173
arrayvec_push_account_info_10_ref 6 0
arrayvec_push_account_info_10_clone 7 1
arrayvec_push_account_info_10_move 7 1
account_meta_array_10_loop 201 195
account_info_array_10_ref_loop 6 0
account_info_array_10_clone_loop 7 1
account_info_array_10_move_loop 7 1

7.3 Msg

Function CU Consumed CU Adjusted
msg10_chars 110 104

7.4 Sysvar Clock

Function CU Consumed CU Adjusted
clock_get_slot 169 163

7.5 Sysvar Rent

Function CU Consumed CU Adjusted
sysvar_rent_exemption_165 150 144

8. Serialization

8.1 Bytemuck Deser

Function CU Consumed CU Adjusted
try_pod_read_unaligned 26 20
pod_read_unaligned 25 19
try_from_bytes 6 0

8.2 Compressed Account Info

Function CU Consumed CU Adjusted
borsh_deserialize 396 390
zero_copy_deserialize 102 96
wincode_deserialize 258 252
bincode_deserialize 3239 3233
borsh1_deserialize 396 390
rkyv_zero_copy_deserialize 172 166
wincode_shortvec_deserialize 263 257

9. Solana Crates

9.1 Msg

Function CU Consumed CU Adjusted
msg10_chars 110 104

9.2 Msg Program Id

Function CU Consumed CU Adjusted
msg_program_id 6833 6827

9.3 Pubkey New From Array

Function CU Consumed CU Adjusted
pubkey_new_from_array 14 8

9.4 Pubkey To Bytes

Function CU Consumed CU Adjusted
pubkey_to_bytes 14 8

9.5 Seed References

Function CU Consumed CU Adjusted
collect_vec_1_seed 18 12
collect_vec_3_seeds 57 51
collect_vec_16_seeds 161 155
collect_arrayvec_1_seed 9 3
collect_arrayvec_3_seeds 27 21
collect_arrayvec_16_seeds 156 150
collect_arrayvec_3_seeds_16_capacity 125 119
array_3_seeds 23 17
array_3_seeds_maybeuninit 20 14
array_3_seeds_maybeuninit_no_transmute 18 12
array_3_seeds_ptr 19 13

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages