Ask Your Question

Fastest way of running sage?

asked 2013-09-08 11:28:34 -0500

Alexandru Papiu gravatar image


So far I have used 3 different "versions" of sage:

  1. the online sage notebook:

  2. the sage notebook that I downloaded and run on Windows 7 thru VirtualBox on an intel core 2duo

  3. the sage in the cloud found here:

Using "time a = factorial(1000000)" I get cpu and wall times of(.41s, .41s) for 1 and 2,13s; 9.53s) for 2. For 3 "time" apparently does not work but it seems slower than 1.

Questions: Why is 1 significantly faster than 2?

How can I test 3?

Is there a way to test entire programs that gives the time for every step.

What is the fastest way to run sage?


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-09-08 12:07:18 -0500

fidbc gravatar image

updated 2013-09-08 12:23:07 -0500


(This was just going to be a comment but it got too long)

  1. Maybe 1 is faster than 2 since that is running natively on the server, the VirtualBox overhead might slow things down.

  2. You can create a worksheet and run the command

    %time a=factorial(1000000)

    Here is what I got. image description

  3. On profiling programs:

    sage: %prun a=factorial(1000000)
             2 function calls in 0.286 seconds        
       Ordered by: internal time        
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            1    0.286    0.286    0.286    0.286    0.286 <string>:1(<module>)
            1    0.000    0.000    0.000    0.000 {method 'disable' of  _lsprof.Profiler' objects}

    More details here.

  4. Perhaps the naive answer is that running it on a "faster" computer would do the job. ;-) My experience back around sage-4.x was that compiling it resulted in faster runs, so my recommendation would be to compile sage on a linux machine.

    Just ran the factorial command and got

    sage: %time a=factorial(1000000)
    CPU times: user 0.27 s, sys: 0.01 s, total: 0.28 s
    Wall time: 0.28 s

    I'm running a compiled sage 5.10 on arch linux.

Hope it helps!

Updated to include running time at

edit flag offensive delete link more


Thanks you, this is really helpful!

Alexandru Papiu gravatar imageAlexandru Papiu ( 2013-09-09 11:28:44 -0500 )edit

answered 2013-09-09 23:37:45 -0500

tmonteil gravatar image

As suggested by @fidbc, it is very likely that your second test is much slower than the other ones because of the following heavy stack: Sage runs on Linux which is emulated by virtualbox which runs on windows! This may also explain why, in this second case, the wall time is much bigger than the CPU time: the wall time also counts the time spent for letting the stack work and the communications among parts of the stack.

Also, this might be due to the fact that an external greedy process in running during your test. To circumvent this possibility, you can use %timeit instead of %time: your test will be run several times and will select the fastest one.

If you want to run Sage on your local machine, i strongly advise to install Linux on an additionnal partition and run Sage directly from it. A lighter solution could be to boot from a live USB key that includes Sage. If you make some tests with those configurations, i would like to see the difference.

If you are interested in saving time without much coding effort, you may be interested in the @parallel decorator.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-09-08 11:28:34 -0500

Seen: 2,322 times

Last updated: Sep 09 '13