Simon Gust
Member
I want to test the speeds of data structures in certain jobs. Some are better at certain things so I'm trying to find the fastest.
I am building a caching system, where I have to store data to be used later due to:
- seperating writing data saves time on some calculations:
I have an array (4000x1000 currently) and each entry can store multiple numbers via bitmasking.
So the base data (the first 8 bytes) don't have complex calculation and can be added with adding or subtracting. But I have some other type of data (byte 31 to 34 and 35 to 42) that are added somewhere between the array population. The problem of course, is that setting an entry without the bitwise is faster but will overwrite the whole entry. So all later bytes I store in a cache that adds all the data at the end. This allows me to do easier calculations first.
- seperating drawing:
My rendering requires a double for loop to draw all pixels onto a surface etc. But I want so save looking up different types of data in different loops, so I can look up all data inside a single double-for-loop. I cannot always setting and resetting surface targets, that is way too slow, so I cache all the data and have it sorted.
My caches can be:
- arrays (1D)
- lists
- queues
So now of course, I'm searching for the fastest to:
- just write data
- the position of each entry is meaningless
- just read data
testing code
The structure that isn't used I have commented out during the tests.
left: without yyc
right: with yyc
So what are your thoughts?
Is this a fair comparison?
Are there alternatives?
I am building a caching system, where I have to store data to be used later due to:
- seperating writing data saves time on some calculations:
I have an array (4000x1000 currently) and each entry can store multiple numbers via bitmasking.
So the base data (the first 8 bytes) don't have complex calculation and can be added with adding or subtracting. But I have some other type of data (byte 31 to 34 and 35 to 42) that are added somewhere between the array population. The problem of course, is that setting an entry without the bitwise is faster but will overwrite the whole entry. So all later bytes I store in a cache that adds all the data at the end. This allows me to do easier calculations first.
- seperating drawing:
My rendering requires a double for loop to draw all pixels onto a surface etc. But I want so save looking up different types of data in different loops, so I can look up all data inside a single double-for-loop. I cannot always setting and resetting surface targets, that is way too slow, so I cache all the data and have it sorted.
My caches can be:
- arrays (1D)
- lists
- queues
So now of course, I'm searching for the fastest to:
- just write data
- the position of each entry is meaningless
- just read data
testing code
Code:
Q = ds_queue_create();
L = ds_list_create();
A[64000] = false;
num = 0;
var time = current_time;
//FUNCTIONS STARTØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØ
for (var i = 0; i < 4000; i++)
{
for (var j = 0; j < 4000; j++)
{
if (i mod 1000 == 0)
{
// array
A[num] = true;
A[num+1] = true;
A[num+2] = true;
A[num+3] = true;
num += 4;
// queue
ds_queue_enqueue(L, true, true, true, true);
// list
ds_list_add(L, true, true, true, true);
}
}
}
repeat (16000)
{
// queue
var a = ds_queue_dequeue(Q);
var b = ds_queue_dequeue(Q);
var c = ds_queue_dequeue(Q);
var d = ds_queue_dequeue(Q);
}
for (var i = 0; i < 64000; i += 4)
{
// array
var a = A[i];
var b = A[i+1];
var c = A[i+2];
var d = A[i+3];
// list
var a = ds_list_find_value(L, i);
var b = ds_list_find_value(L, i+1);
var c = ds_list_find_value(L, i+2);
var d = ds_list_find_value(L, i+3);
}
//FUNCTIONS END ØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØ
var time = current_time - time;
show_debug_message("| Delay: " + string(time) + " ms");
Code:
// previous records
array
5043 ms / 3266 ms
queue
4074 ms / 1521 ms
list
3049 ms / 718 ms
right: with yyc
So what are your thoughts?
Is this a fair comparison?
Are there alternatives?