Page 1 of 1

timing vs size of byte string

Posted: Sat May 24, 2014 6:31 am
by DarScott
The most important chunk operations might be characters. However, for some of what I do, bytes are important. Here are some characteristics of how long it takes to do some things regarding a single byte of a long byte string. I'll start out with deleting a byte at an end.

For a million bytes it takes about 0.4 ms to delete the last byte, but sometimes it can be over 1.5 ms. To delete the first byte of a million byte string takes about 0.5 ms on my computer, but it can take 2 ms.

Re: timing vs size of byte string

Posted: Sat May 24, 2014 6:35 am
by DarScott
The time to get a byte is similar.

Re: timing vs size of byte string

Posted: Sat May 24, 2014 6:43 am
by DarScott
The time to add a byte to the end of a byte string is very small and constant, about 0.0003 ms on my computer (300 ns).

EDIT: And the time to add a byte to the front is about 300 ns plus 60 ns for every 1000 bytes. So, for large strings there is a slight advantage to adding bytes to the back.

Re: timing vs size of byte string

Posted: Sat May 24, 2014 7:04 am
by DarScott
Getting the number of bytes of a byte string also depends on the length. (I think it is remembered though.) Something interesting is going on near a million bytes. Just under that, though, getting the length seems to take 150 microseconds. I have seen it take longer though, and in one test it seems to take around 350 microseconds.

EDIT: In subsequent runs, this has the same pattern as the others, only half the values. I don't know why this chart doesn't have the higher scatter.

I wonder if most operations do two 'the number of bytes' and it is the root of all slowness.

Re: timing vs size of byte string

Posted: Sat May 24, 2014 7:05 am
by DarScott
These tests were made by adding bytes to the end of a byte string and doing tests every 1000.

Re: timing vs size of byte string

Posted: Sat May 24, 2014 8:33 pm
by DarScott
The loop time for touching every byte with 'repeat for each byte' is constant and small, about 260 ns on my machine. The time to touch all the bytes in a byte string with the number of bytes = n is 260n + 70000 in ns. That is about 70 microseconds plus a quarter of a microsecond for each byte.

Re: timing vs size of byte string

Posted: Sun May 25, 2014 6:18 am
by DarScott
The time to double the length of a string as in 'get s & s' is 2 microseconds plus a microsecond for every 3000 bytes of s. A million byte string takes about 340 microseconds to double.