- Make sure your rust application uses https://github.com/gnzlbg/jemallocator as the global memory allocator (when in doubt, grep
jemallocatorin yourCargo.lock). - Install
jemalloc(we'll only needjeprof),dot,ps2pdfandlibunwindon your system. Enable jemallocator'sprofilingfeature (ifjemallocatoris an indirect dependency, one trick to do is to add a dependencyjemallocator = { version = "*", features = ["profiling"] }to your app and let cargo select the||of features for you). export _RJEM_MALLOC_CONF=prof:true,lg_prof_interval:32,lg_prof_sample:19.lg_prof_intervalsets how often profile dump should be written to disk measured in allocated bytes. The value is passed as a power of two, which is 2^32 in our case, i.e. every 4 GiB of allocations of long-lived objects (see https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling).lg_prof_sample:19tells jemalloc to take a profiling sample every 2^19 = 512 KiB.- Running your binary should produce a bun
This file contains hidden or 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
| use std::str; | |
| fn main() { | |
| // -- FROM: vec of chars -- | |
| let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}']; | |
| // to String | |
| let string1: String = src1.iter().collect::<String>(); | |
| // to str | |
| let str1: &str = &src1.iter().collect::<String>(); | |
| // to vec of byte |
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "io" | |
| "net" | |
| "net/http" | |
| "os" |