Performance
Qu is a fast and efficient interpreter. It is significantly faster than
Perl, Python, Ruby and PHP. It even matches the speed of some static
languages.
Here are the result of some programs as found in the
The Computer Language Shootout Benchmarks
tested on an Intel Pentium-4 1.7GHz system using Qu-1.21.
heapsort (100000) |
C (gcc) | 0.05 |
Java * | 0.31 |
Qu -O | 0.76 |
Euphoria | 0.85 |
Qu | 1.46 |
Python2.4 | 3.41 |
Perl5.6 | 4.61 |
Ruby1.8 | 6.47 |
PHP5 | 11.62 |
|
fibonacci (32) |
C (gcc) | 0.08 |
Java * | 0.29 |
Qu -O | 0.54 |
Euphoria | 0.67 |
Qu | 1.31 |
Python2.4 | 5.81 |
Perl5.6 | 9.19 |
Ruby1.8 | 9.45 |
PHP5 | 15.12 |
|
ackermann (3, 10) |
C (gcc) | 0.78 |
Java * | 1.04 |
Qu -O | 4.73 |
Euphoria | 6.74 |
Qu | 33.46 |
Python2.4 | 90.79 |
Perl5.6 | 112.34 |
Ruby1.8 | 191.76 |
|
object (1500000) |
Java * | 0.47 |
C++ (g++) | 0.48 |
Qu -O | 1.61 |
Qu | 2.53 |
Ruby1.8 | 11.02 |
Python2.4 | 11.13 |
Perl5.6 | 33.65 |
|
* interpolated (not actually tested)
values are in seconds.
Here are the Qu programs just in case you want to try them out.
sub ackermann (m, n)
return m
? (n
? ackermann (m - 1, ackermann (m, n - 1))
: ackermann (m - 1, 1))
: n + 1
;;
sub fibonacci (n)
return n > 2 ? 1 : fibonacci (n - 2) + fibonacci (n - 1)
;;
const IM = 139968
const IA = 3877
const IC = 29573
LAST = 42
sub gen_random (max)
LAST = (LAST * IA + IC) % IM
return (max * LAST) / IM
;;
sub doheapsort (a, n)
r = i = j = 0
l = (n >> 1) + 1
k = n
loop
if l > 1
r = a[--l]
else
r = a[k]
a[k--] = a[1]
if k == 1
a[1] = r
return
;;
;;
i = l
j = l << 1
while j <= k
if j < k and a[j] < a[j + 1]
++j
;;
if r < a[j]
a[i] = a[j]
i = j
j += i
else
j = k + 1
;;
;;
a[i] = r
;;
;;
sub heapsort (n)
a = Array.make (n + 1, lambda (i) gen_random (1.0))
doheapsort (a, n)
;;
class Toggle
var state = true
sub __init (start_state)
self.state = start_state
;;
sub value
return self.state
;;
sub activate
self.state = !self.state
return self
;;
;;
class NthToggle is Toggle
var count_max = 3
var counter = 0
sub __init (start_state, max_counter)
super.__init (start_state)
self.count_max = max_counter
self.counter = 0
;;
sub activate
if ++self.counter >= self.count_max
self.state = !self.state
self.counter = 0
;;
return self
;;
;;
sub object (n)
toggle1 = Toggle (true)
for __ in 1, 5
println (toggle1.activate.value)
;;
for __ in 1, n
toggle = Toggle (true)
;;
println
ntoggle1 = NthToggle (true, 3)
for __ in 1, 8
println (ntoggle1.activate.value)
;;
for __ in 1, n
toggle = NthToggle (true, 3)
;;
;;
|