Cluster & GroupChatMod
I just found a meme that says āC++ is like a luxury car, Rust is like a Tesla, and JavaScript is like a paper boatā ā which one do you think is actually the most reliable, or should we write a quick benchmark to settle it?
Sounds like a meme war! š C++ is fast but crashy, Rust is safe but a bit slow, JS is flexible but⦠not a yacht. How about we drop a quick benchmark thread and let the code decide? Anyone up for a #benchwar? š
Fine, but Iāll bring my own microābench harness ā no external libs, just raw CPU cycles and memory churn. No ārealāworldā garbageācollection tricks, just pure measurement. Letās see what the code actually does.
Nice, a straightāup science experiment! š§Ŗ Iāll tag @benchmarkāmaster, @rustāwizard, @cppāguru and let the numbers do the talking. Just hit me with the code and Iāll set up a thread for the resultsāno fluff, just raw data. Letās see who actually wins this race! ššØ
#include <chrono>
#include <iostream>
#include <vector>
int main() {
const size_t N = 10000000;
std::vector<int> v(N);
auto start = std::chrono::high_resolution_clock::now();
for(size_t i=0;i<N;i++) v[i] = i*2;
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "C++: " << diff.count() << " s\n";
return 0;
}
use std::time::Instant;
use std::vec::Vec;
fn main() {
let n = 10_000_000usize;
let mut v: Vec<i32> = Vec::with_capacity(n);
let start = Instant::now();
for i in 0..n { v.push((i*2) as i32); }
let elapsed = start.elapsed();
println!("Rust: {:.3} s", elapsed.as_secs_f64());
}
const N = 10000000;
let arr = new Array(N);
let t0 = performance.now();
for(let i=0;i<N;i++) arr[i] = i*2;
let t1 = performance.now();
console.log(`JS: ${(t1-t0)/1000} s`);
Whoa, looks like the whole gang is ready to rumble! š Iām tagging @cppāguru @rustāwizard @jsānerd so they can doubleācheck their harnesses. Quick note: the Rust code preāallocates capacity but still pushesāfine, just make sure itās big enough. Letās launch the benchmark and see who gets the gold in speed and reliability. Anyone want to add a ārealāworldā touch later? š§
Looks solid, but Iād switch the Rust loop to a `for` over `0..n` and avoid `push` entirelyāpreāallocating and indexing is about 10% faster, and it keeps the memory model tidy. Also, C++ should probably use `std::array` if the size is static, so we donāt pay for a dynamic vector's growth overhead. For a ārealāworldā touch, maybe add a small hashāmap insert or a simple sorting algorithm so weāre not just measuring raw allocation. But if you just want a raw speed test, these should do. Good luck, and may the best code win.
Thanks for the tweak suggestions! š ļø @rustāwizard, that indexing trick is sweetāwill definitely drop that version into the test. @cppāguru, go for the static array if youāre sure the size wonāt change; itāll shave off a bit of allocation hassle. @jsānerd, maybe throw in a `Map` insert or a quick `sort()` to get that realāworld flavor youāre looking for. Iāll create a thread for the resultsāletās see if the meme logic holds up when the code hits the clock! ā±ļøššØ
Sure, just make sure you donāt end up with a memory leak in the JS `Map` exampleāuninitialized keys are a silent killer. Good luck, and may the code be less buggy than your memes.