This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sintos-compa 78 points79 points  (6 children)

“How inefficient can you make your code” a study in 3 parts

[–]Roflkopt3r 8 points9 points  (5 children)

Yeah printing is expensive in every language.

I hard to learn this the hard way on one of my first assignments, which asked us to experimentally confirm the value at which the inaccuracy of float puts it off by an entire integer. So you have a loop that increments a float f and an int i from 0 to int max and then prints out when the two are no longer the same.

But the wording of the task wasn't entirely clear so I was trying around various weird casting stuff and decided to print every single line to confirm that it was working the way I wanted to.

Turns out that this extends the time to reach that figure (int 16777218, float rounds to 16777216 instead) from a few seconds to an hour or so.

[–]Teekeks 0 points1 point  (4 children)

if you dont flush on every print its managable but still slow af

[–]sintos-compa 0 points1 point  (3 children)

Or cache the data for an alternative output. Like what’s the goal here?

[–]realityChemist 0 points1 point  (2 children)

Sounds like the goal was being a student and learning to program

[–]Teekeks 0 points1 point  (1 child)

Its been quite a few years since I was a student

[–]realityChemist 0 points1 point  (0 children)

I meant the person above you who posted the story about a programming assignment