From f9e2e3739a3485d6873b0b77664d62b9f55a6762 Mon Sep 17 00:00:00 2001 From: Kevin Hughes Date: Fri, 14 Apr 2017 18:46:27 -0400 Subject: [PATCH] remove perf tests. They dont use the actual utils so there is no reason to keep them in this state --- play.py | 10 --- tests/perfTests.py | 154 --------------------------------------------- 2 files changed, 164 deletions(-) delete mode 100644 tests/perfTests.py diff --git a/play.py b/play.py index 618f52f89..80f3b2dc8 100644 --- a/play.py +++ b/play.py @@ -1,18 +1,8 @@ #!/usr/bin/env python from utils import resize_image, XboxController -<<<<<<< 48ae7d1910c02bfc04433f31ac9fd14322f7747e -from termcolor import cprint -||||||| merged common ancestors -import tensorflow as tf -import model -from termcolor import cprint -======= from termcolor import cprint -import tensorflow as tf -import model ->>>>>>> split Sample class out of Screenshot class import gym import gym_mupen64plus from train import create_model diff --git a/tests/perfTests.py b/tests/perfTests.py deleted file mode 100644 index 86bf61fce..000000000 --- a/tests/perfTests.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python - -import sys -import time -import array - -import wx -wx.App() - -from skimage.transform import resize -from skimage.util import img_as_float - -import numpy as np - -from PIL import Image - - -# CONSTANTS # -SRC_W = 640 -SRC_H = 480 -SRC_D = 3 -OFFSET_X = 400 -OFFSET_Y = 240 - -IMG_W = 200 -IMG_H = 66 -IMG_D = 3 - - -def original_take_screenshot(): - screen = wx.ScreenDC() - size = screen.GetSize() - bmp = wx.Bitmap(size[0], size[1]) - mem = wx.MemoryDC(bmp) - mem.Blit(0, 0, size[0], size[1], screen, 0, 0) - return bmp.GetSubBitmap(wx.Rect([0,0],[SRC_W,SRC_H])) - - -def modified_take_screenshot(): - screen = wx.ScreenDC() - bmp = wx.Bitmap(SRC_W, SRC_H) - mem = wx.MemoryDC(bmp) - mem.Blit(0, 0, SRC_W, SRC_H, screen, OFFSET_X, OFFSET_Y) - return bmp - - -def original_prepare_image(img): - buf = img.ConvertToImage().GetData() - img = np.frombuffer(buf, dtype='uint8') - - img = img.reshape(SRC_H, SRC_W, SRC_D) - img = resize(img, [IMG_H, IMG_W]) - - return img - - -arr = array.array('B', [0] * (SRC_W * SRC_H * SRC_D)); -def modified_prepare_image(img): - img.CopyToBuffer(arr) - img = np.frombuffer(arr, dtype=np.uint8) - - img = img.reshape(SRC_H, SRC_W, SRC_D) - - im = Image.fromarray(img) - im = im.resize((IMG_W, IMG_H)) - - im_arr = np.frombuffer(im.tobytes(), dtype=np.uint8) - im_arr = im_arr.reshape((IMG_H, IMG_W, IMG_D)) - - return img_as_float(im_arr) - - -def call_original(): - bmp = original_take_screenshot() - vec = original_prepare_image(bmp) - - -def call_modified(): - bmp = modified_take_screenshot() - vec = modified_prepare_image(bmp) - - -if __name__ == '__main__': - import timeit - - try: - n = int(sys.argv[1]) - except (ValueError, IndexError) as e: - n = 100 - - print("# Running tests " + str(n) + " times") - - print("#") - print("# ORIGINAL:") - print(timeit.timeit("call_original()", setup="from __main__ import call_original;", number=n)) - - print("#") - print("# MODIFIED:") - print(timeit.timeit("call_modified()", setup="from __main__ import call_modified;", number=n)) - - -###################################################### -# SOME RESULTS # -# -# Running tests 10000 times -# -# ORIGINAL: -# 1210.20094013 -# -# MODIFIED: -# 313.987584114 -# -# -# Running tests 10000 times -# -# ORIGINAL: -# 1074.97350001 -# -# MODIFIED: -# 270.604922056 -# -###################################################### - - -###################################################### -# RESULTS DURING ACTUAL UTILS.PY PREPARE RUN # -# -# Preparing 4493 samples (8 races) -# -# ORIGINAL CODE: ~280s -# -# MODIFIED CODE: ~90s -# -###################################################### - - -###################################################### -# RESULTS DURING ACTUAL PLAY.PY RUN # -# -# ORIGINAL CODE: -# Screenshot Prepare Image Model Eval -# Avg Times (500): 0.000318816661835 0.136291568279 0.0443236446381 -# -# MODIFIED CODE: -# Screenshot Prepare Image Model Eval -# Avg Times (500): 0.000203844547272 0.0492500219345 0.0412494616508 -# -# IMPROVEMENT (AS % DECREASE OVER ORIGINAL): -# Screenshot Prepare Image Model Eval -# 36.06% 63.86% 6.94% (execution variance - no changes) -# -###################################################### - -