Discuss Scratch

server_tic
Scratcher
3 posts

Are 2 lookup tables for seperate sine and cosine values better than calculating sine and cosine values?

I just want to know, I need the fastest DDA engine…

My real account is @The_Insane_Creator.
Redstone1080
Scratcher
1000+ posts

Are 2 lookup tables for seperate sine and cosine values better than calculating sine and cosine values?

server_tic wrote:

I just want to know, I need the fastest DDA engine…
Do you mean in Scratch? In this case, I'd imagine sine calculation is faster in Scratch because getting items from a list would require more work from the Scratch VM to get list/variable content and return it so it can be used, whereas for sin(n), the VM just returns sin(pi * n) as a 10-digit fixed point number.

Source: this line in the scratchfoundation/scratch-vm repo

Last edited by Redstone1080 (Sept. 28, 2024 15:01:32)


Maintainer of Snazzle | User of Linux (Fedora in particular) | Fan of Rockets
Pufferfish_Test
Scratcher
500+ posts

Are 2 lookup tables for seperate sine and cosine values better than calculating sine and cosine values?

I made a project that benchmarks this and people have reported that list lookups are both slower and faster; it seems to vary depending on the browser and device.
If you're willing to sacrifice some time when a project is loading, you could benchmark this before the project starts properly and pick the best implementation on the fly maybe?

she/her
i'm currently working on:
- HyperQuark, which tries to compile scratch projects to WebAssembly
- SQONS, a “Standardised” Queer Ontological Naming System
- …and probably some other stuff too!
gilbert_given_189
Scratcher
1000+ posts

Are 2 lookup tables for seperate sine and cosine values better than calculating sine and cosine values?

On my machine (My browser / operating system: Linux, Firefox 130.0, No Flash version detected) in TurboWarp, using a LUT is faster with the compiler on than without. Here's my data:

Compiled
Doing 1000000 trials
native: 3.016 s
LUTdeg: 2.904 s
LUTddeg: 2.944 s
LUTcdeg: 2.971 s
LUTmin: 3.007 s
LUTdeg_unit: 2.875 s
LUTddeg_unit: 2.906 s
LUTcdeg_unit: 2.975 s
LUTmin_unit: 2.94 s
LUTdeg_direct: 2.91 s
LUTddeg_direct: 2.977 s
LUTcdeg_direct: 3.039 s
LUTmin_direct: 3.04 s
Suite finished.

Not compiled
Doing 1000000 trials
native: 6.326 s
LUTdeg: 6.612 s
LUTddeg: 6.851 s
LUTcdeg: 6.955 s
LUTmin: 6.91 s
LUTdeg_unit: 6.248 s
LUTddeg_unit: 6.68 s
LUTcdeg_unit: 6.516 s
LUTmin_unit: 6.62 s
LUTdeg_direct: 6.415 s
LUTddeg_direct: 6.446 s
LUTcdeg_direct: 6.618 s
LUTmin_direct: 6.551 s
Suite finished.


And here are the scripts:


If you see a line above this text, it means that below this text is my signature.
This place is just a memory to me, I may return occasionally but I'm busy.
I guess I'm an ATer now.

I think I may have seasoned my posts a bit too much.
Also, my posts are getting lengthy lately. Whoops.


Colored Pencil is supposed to color the siggy, but Scratch says it's too big.


There is nothing here…



don don pan pan
dondo pan pan

Powered by DjangoBB