I am writing some scripts in Python for fun. The particular project I am working on involves factoring large numbers. Even after some optimization based on this algorithm, this will always become a heavy-duty operation for large enough inputs.
In order to be able to work with the factorizations manually later and avoid re-computing, I intend to write them to files in a systematic way. Originally my intention was to avoid re-calculating factorizations, but a collaborator pointed out to me that file I/O is also computationally expensive! My question is this: how expensive does an operation (such as decomposition of a large number into prime factors) need to be in order for it to be worthwhile opening and reading the output from a file rather than re-computing on the fly?
More generally, what factors affect the threshold of when output databases will be cost-efficient? For context, since my algorithm systematically tests divisibility by 2 and 3 and then numbers of the form 6n plus or minus 1 starting from n = 1, the time taken to factorize is currently at O(n**0.5), and is maximally inefficient at prime inputs.