Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy table data directly to RAM using memcpy() #896

Closed
nesbox opened this issue Jul 30, 2019 · 5 comments
Closed

Copy table data directly to RAM using memcpy() #896

nesbox opened this issue Jul 30, 2019 · 5 comments
Assignees
Labels
API Issues related to TIC80 API enhancement Improvement of existing feature or adding something new

Comments

@nesbox
Copy link
Owner

nesbox commented Jul 30, 2019

This would avoid thousands calling of the pix() api to render a game screen, for example.

@nesbox nesbox added enhancement Improvement of existing feature or adding something new API Issues related to TIC80 API labels Jul 30, 2019
@saranvdev
Copy link

Sounds ok

@StinkerB06
Copy link

And maybe also from RAM?

@nesbox
Copy link
Owner Author

nesbox commented Aug 1, 2019

sure, both directions

@StinkerB06
Copy link

Thanks! Are you going to allow for both string and table memcpy()'ing?

@nesbox nesbox added this to the 0.80.0 milestone Sep 27, 2019
@nesbox nesbox self-assigned this Sep 27, 2019
@nesbox nesbox removed this from the 0.80.0 milestone Jul 15, 2020
@nesbox
Copy link
Owner Author

nesbox commented Jul 20, 2020

I wrote a small test to measure poke performance instead of direct variable assignment

-- title:  game title
-- author: game developer
-- desc:   short description
-- script: lua

x=96
y=24
tbl={}

-- check memcpy performance
start=time()

sz=240*136/2

for it=0,1000 do
	for i=1,sz do tbl[i]=i end
end

memtime=time()-start
trace("memcpy pefr is: "..memtime.." ms",2)

-- check poke performance
start=time()

for it=0,1000 do
	for i=1,sz do poke(i-1,tbl[i]) end
end

poketime=time()-start
trace("poke pefr is: "..poketime.." ms",3)

function TIC()
	cls(13)
	spr(1,x,y,14,3,0,0,2,2)
end

and got results

>memcpy pefr is: 6575.1046 ms
>poke pefr is: 7873.2455 ms

which means poke is slightly slower than writing a value to a variable and using memcpy with arrays, unfortunately, doesn't worth it.

@nesbox nesbox closed this as completed Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues related to TIC80 API enhancement Improvement of existing feature or adding something new
Projects
None yet
Development

No branches or pull requests

3 participants