NumPyとCommon Lispの速度比較記事。処理系の起動時間も測ってしまっているので処理自体にかかっている時間を測って比較してみる。

環境は

Core i5 4670 3.40 GHz

Ubuntu 14.04 LTS

Python 3.4.3 + Numpy import numpy as np import time N = 100000 def sumup (n): return sum ( range ( 1 , n + 1 )) def sumup (n): return np.arange( 1 , n + 1 ). sum () def main (): print ( "python with numpy start." ) result = {} for count in range ( 1 , N + 1 ): result[count - 1 ] = sumup(count) print ( "python with numpy end." ) start = time.time() main() elapsed_time = time.time() - start print ( "elapsed_time:{0}" . format (elapsed_time))

SBCL 1.3.11 ( defparameter *n* 100000 ) ( defun sumup1 ( n ) ( declare ( type fixnum n )) ( let (( sum 0 )) ( loop for i from 1 to n do ( incf sum i )) sum )) ( defun sumup2 ( n ) ( declare ( type fixnum n )) ( let (( sum 0 )) ( declare ( type fixnum sum )) ( loop for i from 1 to n do ( incf sum i )) sum )) ( defun sumup3 ( n ) ( declare ( type fixnum n ) ( optimize ( speed 3 ) ( safety 0 ))) ( let (( sum 0 )) ( declare ( type fixnum sum )) ( loop for i from 1 to n do ( incf sum i )) sum )) ( defun sumup4 ( n ) ( declare ( type fixnum n ) ( optimize ( speed 3 ) ( safety 0 ))) ( let (( sum 0 )) ( declare ( type fixnum sum )) ( loop for i fixnum from 1 to n do ( incf sum i )) sum )) ( declaim ( ftype ( function ( fixnum ) fixnum ) sumup5 )) ( defun sumup5 ( n ) ( declare ( type fixnum n ) ( optimize ( speed 3 ) ( safety 0 ))) ( let (( sum 0 )) ( declare ( type fixnum sum )) ( loop for i fixnum from 1 to n do ( incf sum i )) sum )) ( defun main () ( print "common lisp start." ) ( loop for count from 1 to *n* collect ( sumup5 count )) ( print "common lisp end." )) ( time ( main ))