@jim said:
Which is worse: CPU time or Disk I/O time?
You will need to do your own testing, but here's another possible work-around..
in Windows, save the definition as "nul"
(or "\\Device\\Null"
), and Mac as "/dev/null/"
These are special files that will not actually write to disk, but just throw away the data. But the definition path will be changed.
It's not exactly what you are asking for, but maybe better than creating double files on disk.
Thank you for your suggestion, Jim. I have made the test as you suggested:
definition = Sketchup.active_model.entities[0].definition
n = 50
Benchmark.bm do |x|
x.report("save to nul ") { for i in 1..n; definition.save_as("/dev/null"); end }
x.report("save to desk") { for i in 1..n; definition.save_as("/Volumes/.../Desktop/cubes.skp"); end }
end
user system total real
save to /dev/null 7.770000 0.440000 8.210000 ( 8.380249)
save to desktop 8.180000 0.630000 8.810000 ( 10.576788)
There is a marginal improvement. I imagine it would be a greater improvement if the save_as path was a network drive, so well worth noting.
Another lesson I learned in the process was understanding how fast the save_as method was. The component in the benchmark above was 3MB when saved. This works out at 0.055 seconds/MB on my Mac Pro (2008).
This contrasts markedly from the Definitions.load method, which guzzles a lot of CPU (it takes 6 times longer):
model = Sketchup.active_model
n = 50
Benchmark.bm do |x|
x.report("load/save") {
for i in 1..n
definition = model.definitions.load("/Volumes/Storage/Users/Tommy/Desktop/Component.skp")
definition.save_as("/dev/null")
end
}
x.report("save to null ") { for i in 1..n; Sketchup.active_model.entities[0].definition.save_as("/dev/null"); end }
end
user system total real
load/save 59.010000 2.180000 61.190000 ( 61.211738)
save to null 8.720000 0.440000 9.160000 ( 9.310672)
So the way ahead is clear. Save to change the path, then load only once.