Liste des Groupes | Revenir à c arch |
On Thu, 12 Sep 2024 18:33:18 -0700Rust strings _always_ use utf8! If you use the .as_bytes() casting then you can in fact address the underlying u8 bytes, and since you will be working with 7-bit ascii only, that will not make any difference to you.
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
Michael S <already5chosen@yahoo.com> writes:My hardle is relatedd to [0] part rather than to switch/case part.
>On Tue, 3 Sep 2024 17:46:38 +0200>
Terje Mathisen <terje.mathisen@tmsw.no> wrote:
Q&D programming is still far faster for me in C, but using Rust I>
don't have to worry about how well the compiler will be able to
optimize my code, it is pretty much always close to speed of light
since the entire aliasing issue goes away.
I am trying to compare speed of few compiled languages in one
benchmark that I find interesting.
In order to make comparison I have to port a test bench first,
because while most of this languages are able, with various level of
difficulties, to call C routines, none of them can be called from
'C', at least at my level of knowledge.
>
Porting test bench from C to Go was quite easy, the only part that I
didn't grasp immediately was related to time measurements.
>
Today I started Rust port and it is VERY much harder. After several
hours of reading of various tutorials, examples and Stack Overflow
articles I still don't know how to write
switch (argv[1][0]) {
case 't':
case 'T':
x = 42;
break;
}
>
At this rate, I am not sure that my motivation will last long
enough to finish the porting.
Disclaimer: I have very little experience with Rust. The
example shown below looks like Rust but may very well have
syntax errors (or worse).
>
match argv[1][0] {
't' | 'T' => { x = 42; }
_ => { }
}
>
The _ pattern matches anything that hasn't been matched (and
may be necessary, I'm not sure about that).
Accessing nth character of String (or of str? Or &str ? I am still
trying to figure out the difference.) is not as simple as in C or Go.
One person on Stack Overflow said that he was able to figure it out
after he learned the difference between std::string and
std::string_view in C++. May be, I should follow the same process. But
I don't want to. I don't plan to become an expert Rust programmer,
but rather want to do a simple benchmark.
Les messages affichés proviennent d'usenet.