-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed.html
271 lines (205 loc) · 7.07 KB
/
speed.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html>
<head>
<meta name = viewport content = "width=device-width,initial-scale=1">
<link rel = icon href = data/images/favicon.ico sizes = "16x16 32x32 48x48 64x64">
<script src = data/js/setup.js></script>
<script src = data/js/code.js></script>
<script src = data/js/codemirror.js></script>
<link rel = stylesheet href = data/css/fontawesome.css>
<link rel = stylesheet href = data/css/all.css>
<link rel = stylesheet href = data/css/main.css>
<title>JoBase · Performance Comparison</title>
<style>
.graph, .code {
margin: 2em 0
}
</style>
</head>
<body>
<section class = top>
<a href = "/">JoBase</a>
<i class = "fa-solid fa-bars"></i>
<i class = "fa-solid fa-sun"></i>
<a href = lessons>Lessons</a>
<a href = demos>Demos</a>
<a href = games>Games</a>
<a href = reference>Reference</a>
<a href = download>Download</a>
<a href = https://github.com/JoBase target = _blank>
<i class = "fa-brands fa-github"></i>
</a>
<a href = https://discord.gg/DzHyvZfa5q target = _blank>
<i class = "fa-brands fa-discord"></i>
</a>
</section>
<section class = main>
<h1>Performance Comparison</h1>
<p>
JoBase is developed in pure C, which is the fastest programming language.
Let's compare the speed of JoBase with two other popular Python game libraries.
The boxes below show equivalent code in JoBase, Pygame and Pyglet.
</p>
<div class = code>
<div>
<span>JoBase</span>
<span>Pygame</span>
<span>Pyglet</span>
</div>
<div>
<pre code>
import JoBase
group = []
def loop():
for man in group:
man.draw()
image = Image(MAN, randint(-320, 320), randint(-240, 240))
group.append(image)
run()
</pre>
<pre code>
import pygame, random
class Sprite(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.rect = image.get_rect()
self.image = image
pygame.init()
display = pygame.display.set_mode((640, 480))
image = pygame.image.load("man.png")
group = pygame.sprite.Group()
clock = pygame.time.Clock()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
display.fill((255, 255, 255))
group.draw(display)
man = Sprite()
group.add(man)
man.rect.x = random.randint(0, 640)
man.rect.y = random.randint(0, 480)
pygame.display.update()
clock.tick(60)
pygame.quit()
</pre>
<pre code>
import pyglet, random
window = pyglet.window.Window(640, 480, vsync = 0)
image = pyglet.resource.image("man.png")
batch = pyglet.graphics.Batch()
sprites = []
def render(dt):
window.clear()
batch.draw()
x = random.randint(0, 640)
y = random.randint(0, 480)
sprite = pyglet.sprite.Sprite(image, x, y, batch = batch)
sprites.append(sprite)
pyglet.clock.schedule_interval(render, 1 / 60)
pyglet.gl.glClearColor(1, 1, 1, 1)
pyglet.app.run()
</pre>
</div>
</div>
<p>
In the Pygame and Pyglet equivalent, we attempt to batch render the images.
This makes the drawing much faster.
As you can see, JoBase still maintains a stable framerate, even after 2000 images.
</p>
<script>
graph([
{name: "Pygame", color: "variable", file: "pygame"},
{name: "Pyglet", color: "string", file: "pyglet"},
{name: "JoBase", color: "mark", file: "jobase"}
])
</script>
<p>
What if we don't want to render our images in batches?
The code below achieves the same results without batch rendering.
</p>
<div class = code>
<div>
<span>JoBase</span>
<span>Pygame</span>
<span>Pyglet</span>
</div>
<div>
<pre code>
import JoBase
group = []
def loop():
for man in group:
man.draw()
image = Image(MAN, randint(-320, 320), randint(-240, 240))
group.append(image)
run()
</pre>
<pre code>
import pygame, random
pygame.init()
display = pygame.display.set_mode((640, 480))
image = pygame.image.load("man.png")
clock = pygame.time.Clock()
group = []
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
display.fill((255, 255, 255))
for man in group:
display.blit(image, man)
man = image.get_rect()
group.append(man)
man.x = random.randint(0, 640)
man.y = random.randint(0, 480)
pygame.display.update()
clock.tick(60)
pygame.quit()
</pre>
<pre code>
import pyglet, random
window = pyglet.window.Window(640, 480, vsync = 0)
image = pyglet.resource.image("man.png")
sprites = []
def render(dt):
window.clear()
for sprite in sprites:
sprite.draw()
x = random.randint(0, 640)
y = random.randint(0, 480)
sprite = pyglet.sprite.Sprite(image, x, y)
sprites.append(sprite)
pyglet.clock.schedule_interval(render, 1 / 60)
pyglet.gl.glClearColor(1, 1, 1, 1)
pyglet.app.run()
</pre>
</div>
</div>
<p>
The JoBase code remains the same, as it doesn't support batch rendering.
Notice how individually rendering each image affects the performance of Pyglet and Pygame.
</p>
<script>
graph([
{name: "Pygame", color: "variable", file: "pygame-2"},
{name: "Pyglet", color: "string", file: "pyglet-2"},
{name: "JoBase", color: "mark", file: "jobase"}
])
</script>
<p>
JoBase beats the performance of both libraries!
You can create games and animations with thousands of particles without the framerate being affected.
As you explore the JoBase library, feel free to suggest improvements and ask questions on <a href = https://github.com/JoBase/JoBase target = _blank>GitHub</a> or <a href = https://discord.gg/DzHyvZfa5q>Discord</a>.
Your small contributions will help us make JoBase even better.
</p>
</section>
<footer>
<span>
© Copyright <span id = year></span> JoBase · <a href = mailto:hello@jobase.org>hello@jobase.org</a>
</span>
</footer>
</body>
</html>