WORTH's blog

By WORTH, history, 16 months ago, In English

Hello everyone.

Context
TLDR
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I maybe wrong but are u sure that the static buffer array was slower in runtime, not due to compile-time.I didn't saw the code but afaik you might be declaring a large static buffer array which may increase the compile-time significantly

  • »
    »
    16 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    wrong branch

  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I believe the allocation is done at runtime, and the compilation time is not included in the time shown.

    I tried different buffer sizes, the one with $$$2^{20}$$$ took more time, but the $$$2^{16}$$$ one took less time than smaller buffer sizes. You can check the other submissions.

»
16 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I cannot yet understand why first is faster, but note that you use BufReader in both cases, so no need to bufferization on top of it

  • »
    »
    16 months ago, hide # ^ |
    ← Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    Makes sense. I tried using the internal buffer instead of creating a new one (submission).

    It is faster than the previous code, but still slower than the first idea.

    My guess is the number of Strings (one for each input).

    Edit: The default capacity of the strings was 16, which is not enough for 64-bit integers. I increased it to 20 and got close to 200ms (Submission)

    Maybe I can use a single string for primitive types (instead of creating them for each input) and that'll reduce the time.

    Edit 2: I guess this will work fine for now. Maybe in future I'll dig deeper into making the IO faster than this. Thank you for your insight.

»
16 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Could be due to increased CPU cache utilization for input buffers, which leaves less room for other data needed during runtime. Anyway, best way to figure out why is to profile it.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there in Rust something that reads the entire file (using WinAPI or unix system calls), like this in C++?

Spoiler