No video

Pygame vs Raylib vs Arcade Pyglet: Which One Will Suprise You?

  Рет қаралды 31,726

Coder Space

Coder Space

Күн бұрын

Пікірлер: 109
@jaffhooman
@jaffhooman Жыл бұрын
Respect for guys who testing things as librarys etc
@ingframin
@ingframin Жыл бұрын
Python 3.11 did not add just in time compilation. 3.11 is an improvement of the Python VM in how data is managed, especially object types. The bytecode is still interpreted though.
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
Thanks, I was wrong. But just in time compilation for small code fragments is planned to be implemented in 3.12, and for large ones in 3.13
@ArachnidAbby
@ArachnidAbby Жыл бұрын
@@CoderSpaceChannel oh wow, thats awesome. I didn't know they planned on doing this. I kept seeing them saying they wanted to try to avoid JIT for as long as possible in search of other solutions.
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
Found that Arcade performance can be increased by 25% by replacing the line *self.center_x, self.center_y = self.x, self.y* in the SpriteUnit class with *self.set_position(self.x, self.y)* Is this a bug or a feature, I don't know how to interpret it. And you can achieve even better performance if you don't care about collisions between sprites: SpriteUnit: super().__init__(hit_box_algorithm=None)
@DarrenEberly
@DarrenEberly Жыл бұрын
Hi, great video! I'm one of Arcade's maintainers. The difference in setting center_x and center_y vs using set_position is that internally the position in Sprite is represented as a tuple, and the center_x and center_y properties are mostly helper properties to make it easier to set/access just one of the values. So setting these both actually updates the position twice, whereas set_position only changes it internally one time. I'm also curious if this is tested with Arcade 2.6? We have an upcoming 3.0 release that is approximately a year of development ahead of 2.6 and should offer many speedups, as well as alternative classes like BasicSprite which strips out a lot of the unnecessary weight of Sprite so you can build faster Sprites if you don't need some of the extra niceties of the full class. We're also experimenting with a package to provide speedups via Rust, but that is still very early stages and mostly focused on speeding up collision detection at the moment.
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
@@DarrenEberly Thank you for your contribution to the development of Arcade, this is a very promising and convenient library for creating 2D games.
@vladimirkraus1438
@vladimirkraus1438 Жыл бұрын
Wow! pygame-gpu performance is unbelievable... on my MacBook Air M1 I reached 17401 sprites and holding 60 FPS.
@skilz8098
@skilz8098 10 ай бұрын
And there's probably a lot of other tricks on could implement to even improve upon that...
@sorrowseal
@sorrowseal Жыл бұрын
I understand this is a Python comparison, but can't help to wonder what Raylib in C++ could've achieved.
@cookiepolice2086
@cookiepolice2086 Жыл бұрын
I would imagine not much better because raylib python is calling c/c++ functions
@ensarija
@ensarija Жыл бұрын
I have seen test somewhere else, simple setup, but it shows 3-5x increase in speed when using C++ in raylib. Which is expected, since there is no interpreter.
@weirddan455
@weirddan455 Жыл бұрын
I was curious as well so I coded it up in C with Raylib (I'm more comfortable with straight C than C++). The answer is: a lot faster. I downloaded his Python code to compare. Python could render 3,400 sprites at 60 FPS. C could render 44,500 sprites. At 3,400 sprites C was getting ~800 FPS. About a 13x performance difference.
@samdavepollard
@samdavepollard Жыл бұрын
@@weirddan455 nice; thanks for sharing
@smanzoli
@smanzoli Жыл бұрын
Have just tried it here: I tried 2 different ways: Using sprites (textures) and using shapes (drawing filled circles), using both Pygame and C Raylib. (Standard Python 3.7 interpreter, all with same algorithm (no sprite rotation, just borders collision), no numpy, no jit, nothing). As a bonus, also used p5JS for shapes. First using circle shape: Pygame reached 60 fps for 7.5K circles C Raylib reached 60fps for 1.7K circles p5JS reached 60 fps for 1.7K circles So, Pygame, for circle shape drawing, was 4x faster than C Raylib or p5JS. Then I changed for sprite (40x40 png, no rotation): Pygame reached 60 fps for 3K sprites (performance dropped 50% from shapes to sprite, yes, I used convert_alpha()) C Raylib reached 60 fps with 95K sprites p5JS not tested. So, Pygame got half of previous performance and C Raylib improved 53x, being 31x faster that Pygame using textures. For some reason, textures are easy for C Raylib and a pain for Python... and shapes are a bit easy for Pygame and a real pain for C Raylib. Here are the codes (simply to change comments to swap between textures and shapes). The shape I used was a 40x40 png, a ball with transparent background. Environment: old 7 year old laptop: Win10 64, i7 6 gen, nvidia 980m, 16GB DRAM **************************** C Raylib **************************** #include "raylib.h" #include typedef struct Ball { Vector2 position; Vector2 speed; Color color; int radius; } Ball; int main() { const int W= 1600; const int H = 800; //SetConfigFlags(FLAG_VSYNC_HINT); InitWindow(W, H, "Sander"); SetTargetFPS(240); const int N = 1700; //Texture2D textura = LoadTexture("ball2.png"); Ball *balls = (Ball *)malloc(N*sizeof(Ball)); for (int i = 0; i < N; i++) { balls[i].position.x = (int)GetRandomValue(50, W-50); balls[i].position.y = (int)GetRandomValue(50, H-50); balls[i].speed.x = (float)GetRandomValue(-4.0, 4.0); balls[i].speed.y = (float)GetRandomValue(-4.0, 4.0); balls[i].color = (Color){ GetRandomValue(50, 240), GetRandomValue(80, 240), GetRandomValue(100, 240), 255 }; balls[i].radius = (int)GetRandomValue(5, 10); } while(!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); for (int i = 0; i < N; i++) { balls[i].position.x += balls[i].speed.x; balls[i].position.y += balls[i].speed.y; if (((balls[i].position.x + 30) > W) || ((balls[i].position.x - 30) < 0)) balls[i].speed.x *= -1; if (((balls[i].position.y + 30) > H) || ((balls[i].position.y - 30) < 0)) balls[i].speed.y *= -1; DrawCircle((int)balls[i].position.x, (int)balls[i].position.y, (int)balls[i].radius, balls[i].color); //DrawTexture(textura, (int)balls[i].position.x, (int)balls[i].position.y, balls[i].color); } DrawFPS(50,50); EndDrawing(); } free(balls); //UnloadTexture(textura); CloseWindow(); return 0; } **************************** Pygame **************************** import pygame import math import random pygame.init() w, h = 1600, 800 window = pygame.display.set_mode((w, h)) font = pygame.font.SysFont("Arial", 30) clock = pygame.time.Clock() #imagem = pygame.image.load("ball2.png").convert_alpha() def run(): run = True q = 7500 x = [] y = [] vy = [] vx = [] r = [] cor = [] for i in range(q): r.append(random.randint(5, 10)) x.append(random.randint(30, w-30)) y.append(random.randint(30, h-30)) cor.append((random.randint(10, 255), random.randint(10, 255), random.randint(10, 255))) vx.append(random.randint(-4, 4)) vy.append(random.randint(-4, 4)) if vy[i] == 0: vy[i] = 1 while run: window.fill((0, 0, 250)) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break for i in range(q): if y[i] > h-r[i] or y[i] < r[i]: vy[i] *= -1 if x[i] < r[i] or x[i] > w-r[i]: vx[i] *= -1 x[i] += vx[i]; y[i] += vy[i]; pygame.draw.circle(window,cor[i],(x[i],y[i]),r[i]) #window.blit(imagem,(x[i]+20, y[i]+20)) clock.tick() fp = int(clock.get_fps()) txtsurf = font.render("FPS: " + str(fp), True, (0,0,0)) window.blit(txtsurf, (25,45)) pygame.display.update() pygame.quit() if __name__ == "__main__": run() ******************************************** Anyone could explain the huge jump from C Raylib when using textures???
@hexagonaldiy
@hexagonaldiy Жыл бұрын
It's just the comparison I was looking for, I think it's great that you did it, thank you very much!
@bluedragon219123
@bluedragon219123 Жыл бұрын
I'm curious if you could look at Kivy game programming as pygame isn't supported on Android or iOS, there is pygame subset 4 android but that seems out of date and still doesn't support iOS. Mobile platforms are a major market and Kivy seems to be the most recommended even for games. Also what IDE are you using? Is it PyCharm? Still a Great Video! Great Job! :)
@skycloud4802
@skycloud4802 Жыл бұрын
I think Ren'py works for Android but it's not very optimised for that in my opinion, and very visual novel orientated. I think Kivy is still probably the best bet for for python on Android right now
@onesome6091
@onesome6091 Жыл бұрын
great video, and would like to see more with raylib!!!!
@gianlucagiuman6132
@gianlucagiuman6132 Жыл бұрын
Your tutorial are amazing, really impressive the update speed after upgrade to 3.11 !!!
@K5RTO
@K5RTO Жыл бұрын
great episode. i've always wanted to see a comparison between libs. good work!
@TecnocraciaLTDA
@TecnocraciaLTDA Жыл бұрын
AWESOME video, congrats, if you can do more videos like this, pleassse. Also, please make more 3D rendering things on python
@paulojonathan3161
@paulojonathan3161 9 ай бұрын
nice trick of the cached rotations! I learned something today, if I haven't watched this video I'd have never think of it, though I'm familiar with cache.
@andre-le-bone-aparte
@andre-le-bone-aparte 6 күн бұрын
Question: What would PyQt rank in your test?
@danub5551
@danub5551 Жыл бұрын
Damn! The pygame GPU is CRAZY! Do you know when this stuff was implemented? There seems to be essentially no information on this anywhere, but seems to be such a magical way to speed up pygame rendering yet no one is talking about it?
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
this is still under development and the final API may change
@danub5551
@danub5551 Жыл бұрын
@@CoderSpaceChannel yeah, but it seems to be too useful of a feature to miss out on right now
@thinkingspace3438
@thinkingspace3438 Жыл бұрын
@@danub5551 a big missing feature is loading textures with the gpu, but you can use the sdl2 functions with ctypes actually
@distantforest2481
@distantforest2481 Жыл бұрын
They say the api is subject to change but it hasn't changed in a year so I'd say it's safe to atleast test out. At worst you can modify your code to any changes they make
@Johnny-tw5pr
@Johnny-tw5pr 21 күн бұрын
Imagine raylib with GPU.... Infinite power!
@ahmedgado2813
@ahmedgado2813 Жыл бұрын
This was unexpected. I love pygame but I thought it would be the worst. Anyway amazing video. And one more thing how did you install pygame on python 3.11 shouldn't it be not supported yet. I always get an error when using pip
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
pip install pygame==2.1.3.dev8
@alexandrepv
@alexandrepv Жыл бұрын
I've always meant to ask: What voice synthesizer do you use? It's so good :)
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
cloud.google.com/text-to-speech
@Unavailable8923
@Unavailable8923 6 ай бұрын
Raylib is a pure C library with over 50 language bindings. I chose it in part for this reason. After developing a game in Python, you have the option of moving to another language for learning or performance reasons, while still keeping your knowledge of the library and all the same calls.
@alexale5488
@alexale5488 3 ай бұрын
That's so true! I plan to build a game engine for 2D games in Raylib. Python and Raylib works too well. Also, Raylib is even simpler than PyGame and has a better implementation. For example, if you want to get the key inputs only once in PyGame, you're dependent on pygame's own event loop. But in Raylib you have a function call for that and you can associate it with any class.
@Unavailable8923
@Unavailable8923 3 ай бұрын
@@alexale5488 I'm probably switching to Godot. Raylib was fun, but Godot 4.x just has more features out of the box including easy exporting of your game to different platforms.
@vialomur__vialomur5682
@vialomur__vialomur5682 Жыл бұрын
Amazing test thanks a lot for it!
@ronaldosd
@ronaldosd Жыл бұрын
Amazing video, thank you for sharing
@robertfletcher8964
@robertfletcher8964 7 ай бұрын
It would be interesting to also see some significant game logic running. These tests feel like profiling different c library wrappers.
@alexale5488
@alexale5488 4 ай бұрын
Do you recommend me using Raylib for a commerical game? I am considering Godot, but I am a Python engineer and I'd find it more pleasurable to keep everything in Python. I have 1 year experience with PyGame, but Raylib seems more lightweight and more performant.
@SuperGrimmy
@SuperGrimmy Жыл бұрын
In arcade you can cheat and hookup up a compute or transform shader wirting to the position and rotation buffer in the spritelist if you want to get millions of sprites. It's probably cheating.. but you can do it :D
@Temu_ko
@Temu_ko Жыл бұрын
man, I am very goood with Python, but never worked with game engines. Your work is really good! Where can I donate some money?
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
Thanks Button 👍
@SuperGrimmy
@SuperGrimmy Жыл бұрын
You pay a lot just for the call overhead itself in python. By simplifying the code making less methods you can gain quite a bit of extra speed, but I think the classes you made are probably closer to what people make in real life. Maybe the separate translate and rotate method is overkill.
@skilz8098
@skilz8098 10 ай бұрын
That's were a 4x4 matrix class with all of its operators and functions would come in handy.
@smiley2827
@smiley2827 Жыл бұрын
Thanks, it was interesting to watch.
@Unavailable8923
@Unavailable8923 6 ай бұрын
In your Raylib class, every call to update() and draw() creates garbage: a list that is never used. An imperative "for" loop would be more efficient.
@Spelis
@Spelis Ай бұрын
what are the results for python 3.12 and what are they for the new 3.13 beta?
@itnabigator
@itnabigator Жыл бұрын
By just changing self.center_x, self.center_y = self.x, self.y to self.postion = self.x, self.y you can increase arcade test count from 3k to 4k (on my machine). You moving each sprite twice per frame and looks like moving is expensive operation in arcade. It sounds stupid I know but it really works. You can easily achieve 6k on arcade by skipping position changing processing for each sprite. To skip arcade position change processing for each sprite: add to SpriteUnit init: self.position = [self.x, self.y] # use list for sprite coords SpriteUnit def update(self): self.rotate() self.translate() self.position[:] = self.x, self.y # skip setter SpriteHandler: def update(self): self.sprites.update() for s in self.sprites: self.sprites.update_position(s) # update gl buffer. Looks like use sprite to just drawing is overkill. It has too many logic in python.
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
Indeed, it matters. self.set_position(self.x, self.y) i think it's ok to skip setter when you don't need the collision functionality
@itnabigator
@itnabigator Жыл бұрын
​@@CoderSpaceChannel set_postion is just self.position = (center_x, center_y) it still include the same overhead. PS. I found how to get 5k without "hacking" just need to disable hit_box in SpriteUnit: super().__init__(hit_box_algorithm=None)
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
@@itnabigator Thanks, that's pretty useful information when developing with Arcade
@itnabigator
@itnabigator Жыл бұрын
@@CoderSpaceChannel Thanks for your videos $) Without it I will not even try to investigate that.
@rodakdev
@rodakdev Жыл бұрын
You're wok is great! Keep it up!
@Gawain-hi5pd
@Gawain-hi5pd Жыл бұрын
How do I use the gpu with pygame?
@RegisdoPython
@RegisdoPython Жыл бұрын
How technic you use to typewriter constantily and fast?
@jkazulyblanco
@jkazulyblanco Жыл бұрын
Awesome tutorial, I tried pygame cpu and cpu cache using a sprite sheet instead of separate files and the performance is surprisingly the same, spritesheets are better for use with programs like Tiled. Although I have one question, how would the numba and taichi libraries be used in this type of test?
@leobozkir5425
@leobozkir5425 Жыл бұрын
using spritesheets only improves loading time, not performance while the program is running
@DandoPorsaco-ho1zs
@DandoPorsaco-ho1zs 2 ай бұрын
Any updates on this SDL 2 Video?
@Utente1011
@Utente1011 11 ай бұрын
Hi! great job. Do you have any information about CPU and GPU ram consumption?
@shadow_blader192
@shadow_blader192 Жыл бұрын
😎 , cool video!
@PySnek
@PySnek 3 ай бұрын
I wonder how that compares to something like Bevy or naylib (Nim)
@yds6268
@yds6268 Жыл бұрын
I think you should use a sprite sheet instead of individual sprite images. Should make everything faster.
@CoderSpaceChannel
@CoderSpaceChannel Жыл бұрын
thanks, helpful advice 👍
@thinkingspace3438
@thinkingspace3438 Жыл бұрын
it makes stuff faster only for stuff using the gpu i guess, using the same texture means less processing
@yds6268
@yds6268 Жыл бұрын
@ThinkingSpace doesn't rotation and movement use GPU? Changing texture coordinates could be done in vertex shader
@thinkingspace3438
@thinkingspace3438 Жыл бұрын
@@yds6268 gpu can rotate on the go yea, but in cpu cache mode the surface also already exists so it's the same
@skilz8098
@skilz8098 10 ай бұрын
@@thinkingspace3438 Not exactly... If the information is in CPU cache sure the CPU could probably calculate it faster than what the GPU for small data sets could, but when you have large data sets of the same type, the GPU is much faster because of the scale of all of its cores. You are limited by the bus transfer speed from the CPU to the GPU. So sending batches of similar large data to the GPU so that the GPU can do those calculations is much faster than having to go back and forth from the CPU to the GPU and back, etc... hundreds or even thousands of times per frame. This causes a major bottleneck. It is not the same.
@iwavcYT
@iwavcYT Жыл бұрын
How do you like the idea of creating Pacman on pygame?
@Narriz
@Narriz 5 ай бұрын
Thank you
@firstname4337
@firstname4337 4 ай бұрын
should test with pygame-ce (pygame community edition)
@nickgennady
@nickgennady Жыл бұрын
Are the sprites not being batched? I made sprite renderer in C and it can do 100K without breaking a sweat.
@DarrenEberly
@DarrenEberly Жыл бұрын
The problem is moving sprites, not drawing them. Arcade for example can easily draw several hundred thousand static sprites(albeit with a high load time), but moving them requires updating the data in the OpenGL buffers, pygame pulls ahead when using the GPU here because it is doing parts of this in C, whereas Arcade is 100% python.
@mrflexii2067
@mrflexii2067 9 ай бұрын
Quick question - is it better to choose Pyglet or Arcade for game development?
@CoderSpaceChannel
@CoderSpaceChannel 9 ай бұрын
If we talk about 2D games, then Arcade. But this is only for desktops - Windows, Linux, macOS. Arcade is not suitable for Android, you need something based on OpenGL ES or Pygame
@simplyhypixel6876
@simplyhypixel6876 7 ай бұрын
Correct me if I'm wrong but can't the performance of pygame be improved by using the .convert_alpha() method on the loaded images
@CoderSpaceChannel
@CoderSpaceChannel 7 ай бұрын
.convert_alpha() is used for surfaces in software (CPU) rendering. When using the GPU to create a texture from an image, .convert_alpha() will result in an error
@FM-kl7oc
@FM-kl7oc 11 ай бұрын
Would PyGame GPU have any performance benefits from caching the same way PyGame CPU did?
@johnstarfire
@johnstarfire Жыл бұрын
don't know why, but I have python 3.11 and the Arcade test went a little better than the pygame + gpu version, while the raylib was the same as pygame + gpu
@hillybankok
@hillybankok 10 ай бұрын
its probably the hardware that you are using
@niconix_sdp
@niconix_sdp Жыл бұрын
when are you going to make a video of raylib with angle vs pygame
@gameworld5147
@gameworld5147 Жыл бұрын
Your speed is like 7×, can you please slower it down a bit I would be very thankful, and can you please make a game where we will have two ships, one being in our control and the other one will be automatically controlled by computer
@ratefort319
@ratefort319 8 ай бұрын
Is there some good tutorial how to use pygame sdl2?
@tommcmasters
@tommcmasters 7 ай бұрын
you should add pygame2
@ajinkyax
@ajinkyax 10 ай бұрын
did you consider pygame-ce ?
@SkyFly19853
@SkyFly19853 Жыл бұрын
Yeah, other Python game engines are also important.
@philtoa334
@philtoa334 Жыл бұрын
Very Nice .
@boxhead-zk7sn
@boxhead-zk7sn 9 ай бұрын
pls a tutorial about pygame.sdl2_video
@Adi-px8eq
@Adi-px8eq 8 ай бұрын
Arcade is not better in everything though. I tried An nbody simulation with about 500 particles(each only 1 pixel) pygame did perfectly fine with Around 50-60 FPS. But arcade was like 2-5 FPS
@holthuizenoemoet591
@holthuizenoemoet591 Жыл бұрын
But how about ray lib with C? surly that is a lot faster?
@PySnek
@PySnek 3 ай бұрын
Go with Nim (naylib) if you want Python-like syntax and speed
@user-kn6uu8cc6l
@user-kn6uu8cc6l Жыл бұрын
you should compare it with pypy!
@vladimirkraus1438
@vladimirkraus1438 Жыл бұрын
is any of these packages available for pypy?
@user-kn6uu8cc6l
@user-kn6uu8cc6l Жыл бұрын
@@vladimirkraus1438 pygame and raylib yes, arcade maybe, because its pyglet based and it have pypy support
@babaeverruslan5519
@babaeverruslan5519 Жыл бұрын
amongASS
@honaleri
@honaleri 8 ай бұрын
Its definitively not a benchmark test if you use different hardware to get the results. All of them should be benchmarked on GPU or CPU and comparee objectively, otherwise you are fudging the results in favor of Pygame, because you kept reimplementing it just so it would out perform the others, while failing to actually ensure GPUs were used for the others as well. Biased data is useless data.
@davnoa5958
@davnoa5958 Жыл бұрын
Last time i checked, Raylib didn't have any python support (and was almost strictly C++, so that was long ago...), so this news bring me joy. You could also try to use @lru_chache from funktools for sprite operations. Could be helpful. Or not, I didn't checked. (or even better, just @cache because it's the same as @lru_cache(maximize = none)... And as somebody before already pointed out -> JIT is not here yet, but some data management is...
3D Engine in Python. SkyBox, Environment Mapping
9:03
Coder Space
Рет қаралды 25 М.
RayLib 5 Released - The Easiest C/C++ Game Library Just Got Even Better
10:42
👨‍🔧📐
00:43
Kan Andrey
Рет қаралды 10 МЛН
Please Help Barry Choose His Real Son
00:23
Garri Creative
Рет қаралды 21 МЛН
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 9 МЛН
A truly 2D game isn't what you think it is...
13:23
NivMiz
Рет қаралды 41 М.
I Made a Graphics Engine (again)
8:27
Zyger
Рет қаралды 166 М.
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,7 МЛН
Should I have used Unity instead of Raylib for my Indie game?
10:11
Lingon Studios
Рет қаралды 33 М.
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 315 М.
Why I'm Glad I Didn't Use Unity
5:34
DaFluffyPotato
Рет қаралды 612 М.
Pygame CE - Better & Faster
6:29
DaFluffyPotato
Рет қаралды 36 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,5 МЛН
What is the Smallest Possible .EXE?
17:57
Inkbox
Рет қаралды 362 М.
I Made a Graphics Engine
6:42
Zyger
Рет қаралды 249 М.
👨‍🔧📐
00:43
Kan Andrey
Рет қаралды 10 МЛН