JoBase Lessons Demos Games Reference Download

Performance Comparison

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.

JoBase Pygame Pyglet
import JoBase

group = []

def loop():
    for man in group:
        man.draw()

    image = Image(MAN, randint(-320, 320), randint(-240, 240))
    group.append(image)

run()
                    
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()
                    
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()
                    

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.

What if we don't want to render our images in batches? The code below achieves the same results without batch rendering.

JoBase Pygame Pyglet
import JoBase

group = []

def loop():
    for man in group:
        man.draw()

    image = Image(MAN, randint(-320, 320), randint(-240, 240))
    group.append(image)

run()
                    
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()
                    
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()
                    

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.

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 GitHub or Discord. Your small contributions will help us make JoBase even better.