#Proof of work optimization

17 messages · Page 1 of 1 (latest)

eager atlasBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lucid ocean
#

I don't think this includes optimization options?

#

I have never used emcc so I don't really know if there's anything else you would need to consider

#

well you could optimize the line that calculates toHash by using std::to_chars, and reinterpret_cast is always a bit of a red flag, but apart from that I don't think there's really anything interesting going on in this code

#

so it would come down mostly to how good the implementation of SHA256 is, and also how good emcc is

#

imo if you want to compare the performance of different languages like C++ and Rust it would make more sense to compile them to native binaries

#

I don't know a lot about emscripten, but from what I've heard I think Rust has more of a focus on compiling to webassembly than C++ has, so the speed difference might just be down to the toolchain? It's why I suggested comparing native binaries, if you use clang++ for C++ (and rustc for Rust) then the backends is just LLVM in both cases

#

actually, instead of std::to_chars I guess using std::format for the entire line would be the better option, if only because it's a lot closer to what you'd do in Rust

#

it's a C++20 feature

queen patio
#

Go was close to C++'s performance

c++ doesn't give you performance, it gives you control over performance

#

that is not to say that "Rust is universally better than C++ at performance", there are parts where C++ is better at

#

Also, note that micro-benchmarks are meaningless in the sense that they don't represent the real world scenario. It's almost always better to profile in real project and track down the issue that is actually slowing down your program. And this applies to not only C++ but almost any other languages. https://www.youtube.com/watch?v=i5MAXAxp_Tw

https://cppcon.org/

Optimizing Away C++ Virtual Functions May Be Pointless - Shachar Shemesh - CppCon 2023
https://github.com/CppCon/CppCon2023

We all know that Virtual Functions Should Be Avoided. A great many tutorials exist for replacing virtual functions with compile-time polymorphism mechanisms, such as std::variant and templates. But...

▶ Play video
queen patio
#

for gcc and clang you can pass -Wl,--as-needed to linker to omit unused symbols and use flag -flto to enable optimization across TUs. i can't say much about wasm compilers though as i don't use wasm, they might work

queen patio
#

~~std::string toHash = inputString + std::to_string(i);

consider directly calling push_back on inputString, or moving the inputString instead of copying~~

totally forgot that it's within a loop.

#

in this case the same string can still be reused instead of recreating on each iteration

eager atlasBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.