I did this code to compare to Delphi code in Delphi forum TListBox and sorting which ran in my computer compiled in free Lazarus environment at time 7,235 s for generate and insert to listbox, 13,265 s sorting the listbox.
Sorting speed test
import random
import string
import time
try:
import tkinter as tk
except:
import Tkinter as tk
t0 = time.clock()
word_max = 256000
names = [''.join(random.choice(string.ascii_uppercase)
for count in range(6))
for word_count in range(word_max)]
t0 -= time.clock()
print('%i words generated in %.2f s' % (word_max, -t0))
t0 = time.clock()
names.sort()
t0 -= time.clock()
print('Sorted in %.2f s' % -t0)
t0 = time.clock()
root = tk.Tk()
scrollbar = tk.Scrollbar(root, orient=tk.VERTICAL)
names_list = tk.Listbox(root, yscrollcommand=scrollbar.set)
scrollbar.config(command=names_list.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
for name in names:
names_list.insert('end', name)
names_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
t0 -= time.clock()
print('List prepared in %.2f s' % -t0)
root.mainloop()
"""Output
Python3.2:
256000 words generated in 6.64 s
Sorted in 0.58 s
List prepared in 3.49 s
Python 2.6.6:
256000 words generated in 4.40 s
Sorted in 0.54 s
List prepared in 2.93 s
Python 2.7.1:
256000 words generated in 4.02 s
Sorted in 0.43 s
List prepared in 3.26 s
"""
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.