Python speed vs csharp

Siegfried Gonzi siegfried.gonzi at kfunigraz.ac.at
Mon Aug 4 03:47:12 EDT 2003


Siegfried Gonzi wrote:

Only for the sake of completeness. My last version had a minor 
bottleneck. The following Bigloo version is as fast as C .

Suming up your erfc function 10^6 times:

new version: 0.5 seconds
C version: 0.5 seconds

As I wrote giving types in Bigloo renders code effectively. It has also 
the advantage that the compiler becomes very picky and spots a lot of 
type errors; Bigloo is as OCaml for example then. If you do not give 
types Bigloo is as forgiving as what you would assume from Scheme.

S. Gonzi
===== NEW VERSION =====
(module erfc2
    (option (set! *genericity* #f)))

(define (erfc::double x::double )
    (let* (
	  (x::double (exact->inexact x))
	  (p::double 0.3275911)
	  (a1::double 0.254829592)
	  (a2::double -0.284496736)
	  (a3::double 1.421413741)
	  (a4::double -1.453152027)
	  (a5::double 1.061405429)
	  (t::double  (/fl 1.0
			   (+fl 1.0
				(*fl p
				     x))))
	  (erfcx::double  (*fl
			   (*fl t
				(+fl a1
				     (*fl t (+fl a2
						 (*fl t
						      (+fl a3
							   (*fl t
								(+fl a4
								     (*fl t a5)))))))))
			  (exp (negfl (*fl x x))))))
       erfcx))


(define  (do-it)
    (let ((erg::double 0.0))
       (do ((i 0 (+fx i 1)))
	  ((=fx i 1000000))
	  (set! erg (+fl erg (erfc 0.456))))
       erg))

(print (do-it))
======================











More information about the Python-list mailing list