Speykious / cve-rs

Blazingly 🔥 fast 🚀 memory vulnerabilities, written in 100% safe Rust. 🦀
Other
3.72k stars 94 forks source link

Performance #8

Closed RGBCube closed 4 months ago

RGBCube commented 4 months ago

I am very conscious about my SaaS (which has 0 users)'s performance, and I needed to use the transmute feature. However, I do not want to rely on the std implementation as it is UNSAFE.

How does this project compare in speed? Is it as efficient as std mem transmute? If it isn't, I do not want it.

Please sell me this transmute.

Creative0708 commented 4 months ago

I wrote a quick benchmark for our transmute function compared to Rust's unsafe transmute, and here are the (formatted) results on my laptop:

cve_rs transmute f32 -> i32: ~11.771 ns
std transmute f32 -> i32: ~461.12 ps

cve_rs transmute [f64; 1024] -> [u8; 8192]: ~2.1262 µs
std transmute [f64; 1024] -> [u8; 8192]: ~1.9688 µs

Unfortunately, for very very small data types, cve_rs's transmute is much slower (by a factor of 25). However, for larger pieces of data, such as slices, our transmute is comparable to that of Rust's transmute function! Obviously, the memory safety of our transmute function far outweighs the performance penalty. We hope you take this into consideration when selecting which implementation of transmute to use.

You can also clone the repo and run cargo bench to try the benchmarks for yourself.