Skip to content

Lightprotocol/cu-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 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 96 90
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 24 18

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 10 4
push_u64 10 4
push_pubkey 15 9
push_10_u8 84 78
push_10_u64 101 95
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 96 90
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 23 17

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 20 14
find_pubkey_10_iters 38 32
position_pubkey_1_iters 44 38
position_pubkey_10_iters 96 90
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 26 20

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 96 90
update_index 14 8
update_get_mut 14 8
update_iter_mut_find 24 18

2.6 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 202 196
push_10_u64 313 307
push_10_pubkey 382 376
push_u8_with_capacity 120 114
push_u64_with_capacity 120 114
push_pubkey_with_capacity 127 121
push_10_u8_with_capacity 153 147
push_10_u64_with_capacity 149 143
push_10_pubkey_with_capacity 218 212
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 8 2
checked_add_u8_unwrap_or 8 2

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 35 29
array_u8_32_neq 31 25
array_u8_32_neq_deref 35 29
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 30 24
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 16 10
try_borrow_mut_lamports 11 5
can_borrow_lamports 8 2
can_borrow_mut_lamports 8 2
try_borrow_data 15 9
try_borrow_mut_data 12 6
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 171 165

7.5 Sysvar Rent

Function CU Consumed CU Adjusted
sysvar_rent_exemption_165 151 145

8. Serialization

8.1 Compressed Account Info

Function CU Consumed CU Adjusted
borsh_deserialize 428 422
zero_copy_deserialize 130 124
wincode_deserialize 263 257
bincode_deserialize 3231 3225
borsh1_deserialize 428 422
rkyv_zero_copy_deserialize 178 172
wincode_shortvec_deserialize 282 276

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 6953 6947

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages