lutris/tests/benchmark_download.py

51 lines
1.1 KiB
Python
Raw Normal View History

2013-05-25 03:19:32 +00:00
import time
import urllib
import sys
import os
2016-08-06 00:35:47 +00:00
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject
2013-05-25 03:19:32 +00:00
2016-08-06 00:35:47 +00:00
2013-05-25 03:19:32 +00:00
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from lutris.util import http
from lutris.gui.dialogs import DownloadDialog
2016-08-06 00:35:47 +00:00
TEST_URL = "https://lutris.net/releases/lutris_0.3.0.tar.gz"
TEST_FILE_SIZE = 4582508
Gdk.threads_init()
2013-05-25 03:19:32 +00:00
GObject.threads_init()
def timed(function):
def _wrapped(*args, **kwargs):
start_time = time.time()
retval = function(*args, **kwargs)
total = time.time() - start_time
2016-08-06 00:20:24 +00:00
print(function.__name__, (TEST_FILE_SIZE / total) / 1048576)
2013-05-25 03:19:32 +00:00
return retval
return _wrapped
@timed
def test_urlretrieve():
urllib.urlretrieve(TEST_URL, "/tmp/test-dl")
class DownloadDialogBenchmark(DownloadDialog):
def download_complete(self, _widget, _data):
2016-08-06 00:20:24 +00:00
print("Complete")
2013-05-25 03:19:32 +00:00
self.destroy()
Gtk.main_quit()
@timed
def test_download_dialog():
DownloadDialogBenchmark(TEST_URL, "/tmp/test-downloader")
Gtk.main()
test_download_dialog()
2016-08-06 00:20:24 +00:00
# test_urlretrieve()