Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8258495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:33:22+00:00 2026-06-08T02:33:22+00:00

So far, while testing the speeds of different approaches to writing the same function,

  • 0

So far, while testing the speeds of different approaches to writing the same function, I’ve been using the time function, and generally it gives me a good indication of the relative speeds of different functions (since they typically differ by around 100k cycles).

While attempting to find the fastest approach for a factorial function, however, time has been lacking. Not only do these methods seem to differ by only 10k-30k cycles, but their overall time vary by around half that amount too (which is expected, I guess).

The three factorial functions:

(defun factorial-recusion (n)   ; 1st      
  (if (equal n 1) 
      1
      (* n (factorial (- n 1)))))

(defun factorial-loop (n)   ; 2nd
  (let ((solution 1))
    (loop for x from n downto 2
       do (setf solution (* solution x))
       finally (return solution))))

(defun factorial-do (n)     ; 3rd
  (let ((solution 1))
    (do ((x n (1- x)))
    ((< x 2) (return solution))
      (setf solution (* solution x)))))

So, I guess I have two questions:

1.) Which method of factorial should be fastest (if any actually is), and why?

2.) If I were to find out for myself the faster function through a general method, what’s the best way to do so (for some reason I think LOC is a bad indicator of speed)? Perhaps there is a way to view the disassembly of Lisp bytecode? Or maybe there’s a better, more rigorous way?

I’m currently running Linux 3.2.0-26, SBCL, on Ubuntu 12.04 x86-64.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:33:24+00:00Added an answer on June 8, 2026 at 2:33 am

    SBCL does not compile to ‘bytecode’. It compiles to native machine code.

    You can disassemble a Lisp function by using DISASSEMBLE.

    Speed in your factorial function is dominated by bignum arithmetic multiplication once the numbers get into the bignum range.

    To make it clearer: which iteration construct you use, DO or LOOP, does not matter much. Most of the time is spent multiplying bignums. The recursive version also does not make much of a difference.

    That’s a typical benchmark problem: many simple numeric benchmarks are dominated by runtimes of a few arithmetic operations (like multiplication of bignums). They will not measure much of the different in speed of general language operations (like the various types of control flow).

    A slow Lisp with a fast bignum library will likely be faster than an optimizing Lisp compiler with Bignum code written in Lisp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating and testing a mysql join query but each time so far
I've started testing out Nancy in self-host mode. So far, so good apart from
So far I've been using ASP.NET MVC 3 BETA. Everything was working fine till
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I've had a login I have used so far to login while I was
As far as i remember while installing ubuntu,the installer didn't ask me for the
As far as I know, VisualSVN Server is a server while TortoiseSVN is a
I'm trying for a while to work this out with no success so far
I'm new to Java, and while reading documentation so far I can't find any
I've been trying for a whlie on this, and have so far been failing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.