4 ms·
Has anyone compared Crystal and Rust on similar lines?
by sbmthakur 6y ago
Has anyone compared Crystal and Rust on similar lines?
- unixhero 6y agoIt would be cool to see. Crystal-lang isn't finished yet tho. Maybe it's a little too early for that?
- tracker1 6y agoDid a rust build with the following... fn fibonacci(n: u32) -> u32 { match n { 0 => 1, 1 => 1, _ => fibonacci(n - 1) + fibonacci(n - 2), } } fn main() { println!("{}", fibonacci(47)); } size: 2.67kb time: 7.391s I think rust wins :-D --- edit: not sure if I used valgrind/massif right, but the largest values in the output file. mem_heap_B=1816 mem_heap_extra_B=32 I think this means it stayed under 2k ram?
- tracker1 6y agoFor the web server... 3.6mb file using hyper, not the leanest but one of the more popular options. extern crate hyper; use hyper::Server; use hyper::server::Request; use hyper::server::Response; fn hello(req: Request, res: Response) { let response = format!("Hello from {}!", req.remote_addr.ip()); res.send(response.as_bytes()).unwrap(); } fn main() { Server::http("127.0.0.1:3000").unwrap() .handle(hello).unwrap(); } Output from wrk -t8 -c400 -d60s http://localhost:3000/ http://localhost:3000/ Running 1m test @ http://localhost:3000/ 8 threads and 400 connections Thread Stats Avg Stdev Max +/- Stdev Latency 173.31us 88.10us 0.98ms 65.18% Req/Sec 35.06k 13.46k 45.48k 74.99% 8383194 requests in 1.00m, 775.50MB read Socket errors: connect 0, read 0, write 229, timeout 0 Requests/sec: 139487.00 Transfer/sec: 12.90MB According to top, rust_http is using about 2.8mb ram, 630% cpu, and wrk is using 700k and 370% cpu. Though I'm on completely different hardware, but the thing definitely screams... For reference: AMD Ryzen R9 3950X, 64GB DDR4@3200(CL18) under WSL2-Ubuntu (Windows 10 insiders)
- sk0g 6y agoWouldn't processing time depend on your CPU, and unless you run the benchmarks in the article, this comparison would be meaningless?
- tracker1 6y agoDon't have a go environment setup, but could do that. The executable size and memory use was also lower.
- sk0g 6y agoWell to be honest, Go binary sizes are always going to be big, to the benefit of ease of development and deployment. Memory usage, I don't know. The Fibonacci benchmark code was a bit... shit. Do you want to send over your Rust code in a Gist or something, and I can compile and compare?
- tracker1 6y agoIt's in the comment above...