I am just starting to learn Ruby and I am a beginner at Python. So keep

that in mind with this simple test using SciTEVersion 1.59.

The task was to open up an Excel file, read down 1000 lines of data and

close the file.

I was suprised that Ruby 200% faster verses the ‘static’ generated

Python com object. The Python ‘dynamic’ was even slower so I won’t

mention it’s time. Psyco will not help this task either, in fact it

slows it down to 9.2 seconds.

Average of 3 runs- Python time:6.16

Average of 3 runs- Ruby time:2.89

Ruby was 200% faster-Chunky Bacon!

For this specific task, I am sorry to say “Python you’re fired”.

#The Python 2.4.1 Version:

import time

Gime = time.time()

from win32com.client import Dispatch

xlApp = Dispatch(“Excel.Application”)

xl_file = (‘c:\testdata.xls’)

xlApp.Workbooks.Open(xl_file)

excel_cells_total=0

for r in range(1,1001):

xlcell=xlApp.Cells(r,2).Value

excel_cells_total=excel_cells_total+xlcell

xlApp.ActiveWorkbook.Close()

xlApp.Quit

print 'Excel 1000 cells total is ’

print excel_cells_total

print 'Python Elapsed ’

print (time.time() - Gime)

#Python Results:

python -c “import py_compile; py_compile.compile(r’C:\myruby\excel_data_2.py’)”

Exit code: 0

pythonw -u “excel_data_2.py”

Excel 1000 cells total is

16132.9

Python Elapsed

6.26900005341

Exit code: 0

pythonw -u “excel_data_2.py”

Excel 1000 cells total is

16132.9

Python Elapsed

6.08899998665

Exit code: 0

pythonw -u “excel_data_2.py”

Excel 1000 cells total is

16132.9

Python Elapsed

6.11800003052

Exit code: 0

#The Ruby 1.8.2 Version:

time = Time.now

require ‘win32ole’

xlApp=WIN32OLE::new(‘Excel.Application’)

xl_file = (‘c:\testdata.xls’)

xlApp.Workbooks.Open(xl_file)

excel_cells_total=0.0

for r in 1…1000

xlcell=xlApp.Cells(r,2).Value

excel_cells_total=excel_cells_total+xlcell

end

xlApp.ActiveWorkbook.Close()

xlApp.Quit

puts 'Excel 1000 cells total is ’ + excel_cells_total.to_s

puts “Ruby Elapsed %f” % (Time.now - time)

ruby excel_data_2g.rb

Excel 1000 cells total is 16132.9

Ruby Elapsed 2.884000

Exit code: 0

ruby excel_data_2g.rb

Excel 1000 cells total is 16132.9

Ruby Elapsed 2.894000

Exit code: 0

ruby excel_data_2g.rb

Excel 1000 cells total is 16132.9

Ruby Elapsed 2.884000