1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#! /usr/bin/env python
import pygame
from pygame.locals import *
from boxes import BouncingBox
from time import time
pygame.init()
FRAME=3000
screenWidth = 600
screenHeight = 400
numImages = 5
maxTrial = 1 # multiple trials, but hard coded in this test
dirtyList=[]
"""
try:
f=preferences[0][9]
except:
f=preferences[0][9]=open('./logs/Test Results - %s.csv'
%str(datetime.now()),'a')
f.write("\n\nSpeed Test - "+str(datetime.now()))
f.write(",Width (pixels)"+','+"Height (pixels)"+','+
"Trial Runs"+','+"Image Objects Drawn")
f.write("\n,"+str(screenWidth)+','+str(screenHeight)+','+
str(maxTrial)+','+str(numImages))
f.write("\nFile Type"+','+"Time taken to load images to memory"+
','+"Trials (frames per second)")
"""
print "width,height",
print screenWidth,
print ",",
print screenHeight
screen = pygame.display.set_mode( [int(screenWidth),
int(screenHeight)] ) #Screen Set 600x400
pygame.display.set_caption("Sprite Speed Test Window")
GREEN = 0, 192, 0 # green
background = pygame.Surface( (screenWidth,screenHeight) )
background.fill(GREEN)
screen.blit(background,[0,0])
pygame.display.flip()
start = time()
frameList = [
pygame.image.load("./art/BMP24/1.bmp").convert(),
pygame.image.load("./art/BMP24/2.bmp").convert(),
pygame.image.load("./art/BMP24/3.bmp").convert(),
pygame.image.load("./art/BMP24/4.bmp").convert(),
pygame.image.load("./art/BMP24/5.bmp").convert(),
pygame.image.load("./art/BMP24/6.bmp").convert(),
pygame.image.load("./art/BMP24/7.bmp").convert(),
pygame.image.load("./art/BMP24/8.bmp").convert(),
pygame.image.load("./art/BMP24/9.bmp").convert(),
]
#make our groups
group1=pygame.sprite.RenderUpdates( BouncingBox(frameList,(0,0)) )
group2=pygame.sprite.RenderUpdates(BouncingBox(frameList,(40,40)) )
group3=pygame.sprite.RenderUpdates(BouncingBox(frameList,(80,80)) )
group4=pygame.sprite.RenderUpdates(BouncingBox(frameList,(120,120)) )
group5=pygame.sprite.RenderUpdates(BouncingBox(frameList,(160,160)) )
print (time()-start) ,
print " -- Time to load"
groups=[group1,group2,group3,group4,group5]
"""while 1:
try:ft=ftArr[t]
except:
print "\nTest Complete\n"
break
f.seek(0,2)
f.write(str('\n'+ft[1]+' Speed Test'))
f.seek(0,2)
start=time.time()
f.write(',')
f.write(str(time.time()-start))
"""
print time()-start
for aTrial in range(maxTrial):
for frame in range(FRAME):
dirtyList=[]
for image in range(numImages):
#move / collision detection
groups[image].update( screenWidth,screenHeight )
#individually blit each image group - add to list for update
dirtyList.extend(groups[image].draw(screen))
#draw the images flip/update
pygame.display.update(dirtyList)
for image in range(numImages):
groups[image].clear(screen, background)
print 1/((time()-start)/FRAME)
"""f.seek(0,2)
f.write(','+str(1/((time.time()-start)/r)))
screen = pygame.display.set_mode([1200, 900])
boxesTwo.add(UpDownBox([pygame.image.load("goblin.png")], (0,300)))
background = pygame.image.load("Room.gif")
#background.fill(pygame.image.load("Room.gif"))
screen.blit(background, [0, 0])
pygame.display.flip()
boxesTwo.update(pygame.time.get_ticks(), 700)
rectlist = boxesTwo.draw(screen)
pygame.display.update(rectlist)
start = time()
for i in range(2000):
boxes.update(pygame.time.get_ticks(), 700)
boxesTwo.update(pygame.time.get_ticks(), 700)
rectlist = boxesTwo.draw(screen)
rectlist.extend(boxes.draw(screen))
pygame.display.update(rectlist)
boxesTwo.clear(screen, background)
boxes.clear(screen, background)
print 2000/(time() - start)
"""
|