|
is locking stdout for a long time like that an issue? I don't really know what its implications are tbh. I personally would be tempted to populate a vec then write out in one go after
|
# ? Dec 12, 2023 00:05 |
|
|
# ? Mar 28, 2024 19:58 |
|
Locking stdout is purely a process-internal thing, not something with some kind of OS-level effect. ...if that's what you're wondering.
|
# ? Dec 12, 2023 00:07 |
|
sure yeah, thanks
|
# ? Dec 12, 2023 00:18 |
|
gonadic io posted:is locking stdout for a long time like that an issue? I don't really know what its implications are tbh. I personally would be tempted to populate a vec then write out in one go after I tried that first, populate a vector with ints. Use println! and iterators to print it in one go. I could not get either print or println work fast enough. With n=200000 writing to stdout gave a 0,4s execution time. With any kind of print it was over 1s with my (lack of) skill.
|
# ? Dec 12, 2023 00:32 |
|
You definitely want to lock rather than call print in a loop because each print call locks and then unlocks stdout anyway. I meant writing to a vec and then calling write on the vec as you did inside your inner loop. But it's probably a pretty moot point if locking stdout for your program is not an issue
|
# ? Dec 12, 2023 00:35 |
|
This is just an algorithm course, so nothing serious. I began learning rust two weeks ago, because I needed a compiler which babysits me. We have 100 different algorithms to implement, and now after a soft start the tasks seem to get stricter. One thing I did not try out was storing the values to vector and then writing it instead of printing. Iterating a vector of 200k indexes adds an extra delay though, so just writing the data after each calculation is done seems to be faster.
|
# ? Dec 12, 2023 00:42 |
|
being babysat by a compiler owns
|
# ? Dec 12, 2023 00:44 |
|
Before implementing a command line argument tool in "main" bin, I used a bin for each day in advent of code. Now I wonder how can I run only tests for day_13.rs for example. They are in end of day_13.rs Rust code:
It just spams my terminal with useless crap currently :I E: Heh, the "Run Test" button above mod tests in day_13.rs in VSCode magically told me the correct command: code:
Ihmemies fucked around with this message at 19:35 on Dec 13, 2023 |
# ? Dec 13, 2023 19:32 |
|
there's also a -Z for inexact matching
|
# ? Dec 13, 2023 19:52 |
|
There’s also a half decent cargo-aoc plugin out there which greatly simplifies this stuff, if wrestling with a cli tool isn’t something you actively enjoy doing. (Its “generator” feature is flaky but also just not necessary.)
|
# ? Dec 14, 2023 03:48 |
|
bitprophet posted:There’s also a half decent cargo-aoc plugin out there which greatly simplifies this stuff, if wrestling with a cli tool isn’t something you actively enjoy doing. (Its “generator” feature is flaky but also just not necessary.) I run the code on my linux server, because setting up stuff there is so much easier. So program runs on VSCode's terminal window. You mean this onehttps://crates.io/crates/cargo-aoc ? Hmm maybe I should test it, thanks. Although since I started learning rust like 2 weeks ago maybe it's good first to do things more manually.
|
# ? Dec 14, 2023 09:56 |
|
Ihmemies posted:I run the code on my linux server, because setting up stuff there is so much easier. So program runs on VSCode's terminal window. Granted, I then put AoC down a few days into it, but that wasn’t the plugin’s fault, just realizing AoC wasn’t a good use of my time right now. (Even those 4 days were a great boost to my Rust tho!)
|
# ? Dec 14, 2023 23:31 |
|
my aoc hot tip is the include_str macro (or include_bytes when you want to shave some microseconds). gently caress reading from files at runtime
|
# ? Dec 14, 2023 23:51 |
|
I have a binary file format that I'd like to parse into a Rust structure and I'm wondering if serde is the wrong crate for it. A few issues that I've run into: 1) There's padding/unused bytes in the file format and serde doesn't seem to have a way of annotating something to the effect of "for this next field, fseek two bytes ahead", nor does it seem to be obvious that serde would treat a PhantomData<u16> as padding. (Besides, manually inserting padding fields into the struct just so serde does the right thing feels a bit funny anyway.) 2) There are lots of bitfields in the file format that I'd like to expand as enums with two discriminants. The problem seems to be that serde (reasonably) doesn't expose consuming data smaller than a byte, nor does it let me read all the bitfields in a byte and then produce multiple types. Seems like the only way to do this is to just implement the entirety of Deserialize on my structure and doing everything manually. (edit: or just read in a blob of [u8] and std::mem::transmute stuff out as I see fit, which I'm not opposed to, per se, but...) If that's the best way, then fine, but I suspect either serde is the wrong crate or I'm approaching this wrong? Dijkstracula fucked around with this message at 20:00 on Dec 16, 2023 |
# ? Dec 16, 2023 19:57 |
|
Take a look at nom, perhaps?
|
# ? Dec 16, 2023 20:06 |
|
you could probably write a custom deserializer for that field and do the seeking you want, but I agree that nom is probably a better fit
|
# ? Dec 16, 2023 20:13 |
|
I think scroll is a popular crate for this kind of usecase. You might also want to have a look st zerocopy or watto (disclaimer: I worked on watto).
|
# ? Dec 16, 2023 20:23 |
|
Serde is not a parsing library.
|
# ? Dec 16, 2023 21:05 |
|
tinaun posted:Serde is not a parsing library. Thanks, all- sounds like nom is the thing I should use.
|
# ? Dec 16, 2023 21:17 |
|
BitTorrent uses Bencode and Bencode already has a serde implementation. It’s really easy to use a serialization library with a serialization format, especially when the work has already been done for you. Not so much for ad hoc bit twiddling.
|
# ? Dec 16, 2023 21:27 |
|
|
# ? Mar 28, 2024 19:58 |
|
I am learning structs are quite handy. For a simple struct like this:Rust code:
So it checks if the coord fits certain bounds. AoC has different sizes of maps and doing always the same bounds checking individually in different solutions starts to suck. Then I realized you can write cool comments like that, so my IDE shows tooltips for my own functions, just like it does for STD's functions. Sweet.. AoC day 17 progress is not great, but not terrible. My utils.rs is growing in functionality at least. First I used usize as coords, then I thought about what if I want to take a cruise around origin.. and realized I need to support negative coordinates too. Ihmemies fucked around with this message at 17:29 on Dec 17, 2023 |
# ? Dec 17, 2023 17:27 |