This is just a toy example but I was wondering what the best (memory and performance wise) way is to store partitions of a fixed integer n, i.e. lists of positive integers which sum up to n.
Currently, I’m using Array{Int8,1} for the partitions and Array{Array{Int8,1},1} to store all the partitions. But I think this is not optimal.
julia> @time P = partitions(90)
4.301507 seconds (56.63 M allocations: 6.239 GiB, 34.52% gc time)
This is quite a lot of memory allocated compared to what I actually have to store. The number of partitions of 90 for example is 56634173, so this is much less than 56634173*90/1000^3 = 5.1GiB of data (ignoring pointers etc.).
Interesting, thank you. But I fear this is useless. This implementation does not store the partitions, it just prints (visits) them. In fact, in the code for the benchmark you find the comment “# – first comment out println in VISIT”.
This would be equivalent to not push the partitions into the array. If I just do the visit, I’m a bit more efficient:
What I don’t really understand is that you show the results from @time but that gives the total number of allocations in the algorithm that creates P but doesn’t say much about the size of P itself. Maybe you just do a bunch of non-needed allocations in partitions?
So, maybe it’s 16 bytes for 3 8-bit integers plus pointers etc!? I don’t know what summarysize is.
I checked allocations using julia --track-allocation=user and as far as I can tell the only allocations came from the push!(P,part) for each partition found.