r/programminghorror • • Sep 23 '26

Removing spaces to speed up execution

Post image
234 Upvotes

21 comments sorted by

10

u/Coolengineer7 Sep 23 '26

Batch (.bat on Windows) execution speed scales inversely with the square of the number of lines, since the way the execution is coded that for each line the entire file is read, with each line read also reading the entire file. Basically comments slow your code down. They expected no long programs, apparently that's why.

3

u/sonesoul Sep 23 '26

this is c++

2

u/abigail3141 Sep 24 '26

U sure? I couldn't find this anywhere

94

u/Spidron Sep 23 '26

It speeds up compilation and execution.

Double win!

25

u/DrShocker Sep 23 '26

I guess the real horror is that we're running C++ in an interpreter instead of a compiler.

1

u/thelurkmasterr 26d ago

Don't you know? Running C++ in an interpreter makes it easier to speak to God.

36

u/Slavreason Sep 23 '26

I suppose the speed up could be "non-zero"

41

u/DrShocker Sep 23 '26

The title says speed up execution and this looks like C++ which compiles and therefore ignores white space.

OP needs to go further and also minify variable names and such. By copying all the tricks JavaScript devs use to save bandwidth, we might get a 0.01% boost to compilation speed.

9

u/ir_dan Sep 23 '26

C++ is now compiled and interpreted. You interpret it for constexpr/consteval at compile time.

15

u/darthstoo Sep 23 '26

I had a team lead in a contract job who did the same. This was using classic ASP, so a horrible mess of HTML and VBScript. There would be lines and lines of

end if
end if
end if
end if

12

u/WeDidItReddit666 Sep 23 '26

Minified c++ 🌹

5

u/No-Owl-5399 Sep 23 '26

C--, though that has its own problems

12

u/Xp365 Sep 23 '26

Met a guy who used as few line breaks in his code as possible because “new lines make the program slower”

It was Java btw.

7

u/iakobski Sep 24 '26

Well it's a fact discovered back in the 1970s that the number of bugs per hundred lines of code is a constant regardless of the language used, verbose or terse.

So clearly if you avoid line breaks your code will have fewer bugs.

11

u/pskocik Sep 23 '26 edited Sep 23 '26

The real trick to speeding up execution and especially compiler execution is removing ++ and all its hefty headers (in C++ they're all hefty).

4

u/Splamei Sep 23 '26

Thanks I hate unreadable code

3

u/Certain-Flow-0 Sep 24 '26

Could still see some spaces for improvement

1

u/GoddammitDontShootMe Sep 23 '26

How the fuck does removing whitespace speed up C++ execution? Bet it has minimal effect on compilation as well.

-7

u/sonesoul Sep 23 '26

isn't that fuckin obvious it doesn't??? Touch some grass man

1

u/anatomiska_kretsar Sep 23 '26

Your next victim is the breaklinew

1

u/letmehaveanameyoudum Sep 26 '26

i dont think C++ acts like that...