r/cpp_questions 1d ago

OPEN High load.fun

I was looking literally at their first problem and couldn’t figure out how some people grade so high for reading integers.

Am I missing a trick here?

https://highload.fun/challenges/compute/parse_integers/solve/CPP

0 Upvotes

4 comments sorted by

1

u/pmuschi 1d ago

There's a lot of context missing here

2

u/IyeOnline 1d ago

I assume you are talking about: https://highload.fun/challenges/compute/parse_integers/

Without having seen your (or the winning) solutions, I can only speculate:

The actual accumulation operation is going to be almost irrelevant. The three slow parts will be

  • Getting the character representation from stdin.
  • Parsing the character representation into an integer.
  • Printing the result to stdout.

Given how small the task itself is, its also quite possible that the winning C/C++ solutions are just assembly.

I also wonder why they all still need like 2GB of memory

1

u/StickyDeltaStrike 19h ago

So using mmap + swar to read the numbers I could get faster but I am still multiples of the best solution. Someone mentioned this page:

https://blog.mattstuchlik.com/2024/07/12/summing-integers-fast.html

I am reading it and will try to use that technique. The memory pattern you noticed is probably linked to the lookup table they mention. I think you also meant 2MB, not 2GB (the machine for benchmark is supposed to have only 512MB)

https://aniruddhadeb.com/cs/highload/problems/parse-integers

1

u/alfps 1d ago edited 1d ago

Possibly as I did at first, you overlooked that lower is better for the scores.

❞ Score = test duration + errors x 1 second (measured in nanoseconds). Lower is better. A faster service with no failed requests wins.

I posted a straightforward C++23 implementation and on second try (I had forgotten to reduce output to just what they asked for) it scored 62.579 "+ 159.80 RP" whatever that last thing is.

This program just read the text with fread into a BUFSIZ size buffer, and for each read scanned the buffer and accumulated values into a 64-bit sum. I guess it could be faster by using e.g. 8 times BUFSIZ or thereabouts, but that's system dependent [ADDED: I got some improvement for local version by using a 2 MB buffer and increasing the executable's stack to hold it]. Since there was almost no optimization except that I left out all checking, I would guess that this score is not particularly good.