Deutsch   English   Français   Italiano  
<v916b5$3g9mg$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Jeff Barnett <jbb@notatt.com>
Newsgroups: comp.lang.lisp
Subject: Re: Optimization flag for unchecked fixnums in SBCL?
Date: Wed, 7 Aug 2024 19:17:22 -0600
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <v916b5$3g9mg$1@dont-email.me>
References: <87h6bwrufd.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 08 Aug 2024 03:17:25 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4c88019076f991b6b0636f6af8ebef21";
	logging-data="3679952"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX186Hh2ptutp2gr8AvHawLg1XnxjS735Fjc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CMDZiiZp5x6xRJlz5t3Dlemhjs4=
X-Antivirus-Status: Clean
X-Antivirus: AVG (VPS 240807-12, 8/7/2024), Outbound message
Content-Language: en-US
In-Reply-To: <87h6bwrufd.fsf@nightsong.com>
Bytes: 3050

On 8/7/2024 1:42 PM, Paul Rubin wrote:
> I looked in the manual and didn't see a way to do this.  The following
> Haskell code (Euler problem 14) takes about 0.5 seconds on my old laptop:
> 
>      cl :: Int -> Int
>      cl n = if odd n then 3*n+1 else n`quot`2
>      dl n = (1+) . length . takeWhile (/= 1) . iterate cl $ n
>      main = print . maximum $ [(dl n, n) | n <- [1..1000000]]
> 
> Int is Haskell's built-in fixnum type.  Integer is bignums and that
> version takes about 7 seconds.
> 
> The below CL version takes 5 seconds (this is chopped down from a
> memoized version that takes about 0.2 seconds).  I tried a few different
> ways to tell the compiler that `collatz' should take and return fixnums,
> but I didn't find the right way.  Any help?  Thanks.
> 
>      (defun collatz (n)
>        (cond ((oddp n) (1+ (* 3 n)))
>              (t (floor n 2))))
> 
>      (defun clen (n)
>        (cond ((= n 1) 1)
>              ((<= n 0) 'crash)
>              (t (1+ (clen (collatz n))))))
> 
>      (defun run (&optional (n 1) (mi 0) (ma 0))
>          (if (> n 1000000)
>            (list mi ma)
>            (let ((a (clen n))
>                  (nn (1+ n)))
>              (if (> a ma)
>                  (run nn n a)
>                  (run nn mi ma)))))
>      (print (run))
>      (terpri)

As a start, did you you try defining collatz and clen with defsubst? Did 
you try using declarations and their cousins? And did your CL system 
provide a decent, declaration-sensitive compiler?

In other words I'm not sure how and what you told the compiler or what 
compiler you were telling. What I recall about this muddle is that what 
a compiler (and system) did with declaration type things was highly 
implementation dependent so wouldn't be quite sure what to advise you.

Other than use defsubst. That should open code most anything in most any 
CL compiler-based system.
-- 
Jeff Barnett