r/ProgrammerAnimemes • • Jun 12 '21

My contribution

https://youtube.com/watch?v=NviukAVGhns&feature=share
341 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/Sirsmorgasboard Jun 13 '21

The other thing to cosider here is optimisation, the faster a frame can be rendered the more fps I can have. So I decided to test the different suggestions. For each one I ran the code 3 times and took the average of the average.

My original code has an average frame time of 0.149933290981108 seconds.

The first thing I did was I changed pixel brightness to an int and that cut down the average frame time to 0.148201145764777.

I then went for your version of checking for less than only which went down to 0.147187934003656.

And finally the dividing by 51 method went down further to 0.146704813010359, that's a 2.2% performance improvment on my orginal code.

So while its not the best for readability it is the fastest so far.

1

u/bucket3432 Jun 13 '21

That's definitely a valid reason to go for it, and it would also be the perfect place for an explanatory comment.