The "IT DOESN'T WORK!" thread

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The "IT DOESN'T WORK!" thread

Postby Yakk » Mon Jul 15, 2019 1:59 pm UTC

Pass -O2 to the compiler and it will finish in seconds.

You have many billions of steps that do absolutely nothing. By default C++ compilers say "ok, I'll do them" unless you ask for it to optimize.

The Java compiler probably has non-zero default optimization.

The next biggest problem would be how the language couples with standard out. One language may do more or less flushing than the other by default.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xanthir
My HERO!!!
Posts: 5426
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby Xanthir » Mon Jul 15, 2019 10:17 pm UTC

Lots more than billions, fwiw. 32768 is 2^15; three nested loops means 2^45 total invocations of the innermost body, which is about 30 trillion.

Yakk wrote:
The next biggest problem would be how the language couples with standard out. One language may do more or less flushing than the other by default.

That shouldn't matter much here; it's only printing in the outermost loop, so at most 30kish print statements. Depending on flushing, that can make it take a few extra minutes, at most.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The "IT DOESN'T WORK!" thread

Postby Yakk » Tue Jul 16, 2019 2:08 am UTC

*nod*, I did the math for the steps between the prints. 2^15^2 is about a billion. Then you have 32 thousand of those. :)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xanthir
My HERO!!!
Posts: 5426
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby Xanthir » Thu Jul 18, 2019 4:05 pm UTC

Ah, makes sense. I figured the innermost body was the "do nothing" thing we were counting, which executes trillions of times regardless of what the outer loops were doing. ^_^
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 16 guests