选自http://modthemachine.typepad.com/my_weblog/2010/03/iproperty-performance.html
Here’s some performance data regarding using Inventor and Apprentice to work with iProperties. I found this interesting and think it will be useful when architecting your programs so you fully understand the advantages and disadvantages of different approaches.
本文中我的同事Brian使用学徒服务器和InventorAPI对iProperties进行操作,发现了一些有趣的结果。
All of the test results shown below are for processing 1000 unique files.
每种测试处理了1000个不同的文件
Test 1 – Open, Edit, Save, Close
This test opened each of the 1000 files, edited the value of two iProperties, saved the document, and closed it.
测试1 - 打开,修改,保存,关闭
- Apprentice – 116 seconds.
学徒服务器 - 18秒 - Inventor (visible document) – 1068 seconds. This test opened the documents visibly by setting the second argument of the Documents.Open method to True.
Inventor (界面可见) - 1068秒。该测试显式打开文档 - Inventor (invisible document) – 238 seconds. This is the same as the test above but opens the documents invisibly by setting the second argument of the Documents.Open method to False.
Inventor (界面不可见) - 238秒。该测试打开文档,但让其不可见(隐式)
The biggest difference is between opening the document visibly or invisibly. When a document is opened invisibly, Inventor is able to optimize the open and not read all of the file. Opening a file invisibly is similar to the time it takes in Apprentice, as shown by test 2 below. However, for test 1 Apprentice is still twice as fast. Two things account for the extra time spent by Inventor; changing the property value and saving the document. Changing the value of an iProperty in Inventor is transacted, meaning that you can undo the operation. Transacting has some overhead which accounts for some of the time. Apprentice doesn’t have any transaction capabilities so it doesn’t have this overhead. The other big difference is the save. To save an iProperty change in Inventor you need to save the entire document using Document.Save. In Apprentice you can save just the iProperty portion of the document using PropertySets.FlushToFile.
测试中发现,时间上的差别来自打开文档隐式打开文档,Inventor可以以优化的性能打开,但不会读取所有数据。学徒服务器也是隐式打开,但速度更快。这里有两个因素:修改iProperty和保存文档。如果用Inventor API,修改iProperty将会记录到事务,意味着你可以撤销(undo)。所以占用了一定时间。而学徒服务器没有事务。另外的大差别就是保存,Inventor API需要调用Document.Save, 意味着整个文档的保存工作要做一遍。而学徒服务器只需要调用PropertySets.FlushToFile即可。
Test 2 – Open, Read, Close
This test also operated on all 1000 files by opening a file, reading property values, and closing the document.
测试2 - 打开,读取和关闭
- Apprentice – 92.341 seconds
学徒服务器 - 92.341秒 - Inventor (invisible document) – 100.374 seconds
Inventor (隐式) - 100.374秒
These numbers show that there isn’t a lot of difference between invisible Inventor and Apprentice when you don’t do anything that’s transacted and you don’t save the document. This is particularly important for add-in writers to understand since you can’t use Apprentice within an add-in.
可见,如果只是读取,两者差别不大。而我们知道插件不能使用学徒服务器,因此当你的插件程序读取iProperty时,可考虑隐式打开。不要总显式打开。
Test 3 – Open, Close
This test uses VB.Net to open and close the same 1000 files. It opens a file, reads the file into memory, and closes the file. It is a pure VB.Net program and has nothing to do with Inventor. I wrote this program to help understand how much of the time is spent on general overhead of reading the file and how much time is spent by Inventor or Apprentice actually doing the work they need to do. As you can see, most of the time used by Apprentice or Inventor is system overhead of opening and reading the file. Anytime you have to read or write data to a hard drive, performance will be slow.
测试3- 打开,关闭。该测试用VB.Net打开关闭1000个文件,只是读取,什么事都不做。结果如下 77.69秒。可见无论是学徒服务器或Inventor API,读取方式的情况下,打开和关闭是最耗费时间的,一旦文档调入到内存,很多工作做的很快。
- VB.Net – 77.69 seconds
Summary
If you need to write a utility to manipulate iProperties, using Apprentice will allow you to create the fastest program. However, if you just need to read iProperty data, opening documents invisibly in Inventor is almost as fast and a good alternative. Remember that Apprentice cannot be used within an add-in. If you need to do a lot of iProperty processing (writing and saving) through an add-in it might be worth creating a separate exe that uses apprentice that your add-in uses. You need to be careful that those documents are not currently open in Inventor.
总结:如果你想操作iProperties,显然最佳选择时学徒服务器。如果你只是读取,用Inventor API (隐式打开文档)也是不错的。而且记住学徒服务器无法在插件中使用。如果你的插件某个环节必须要操作大量的文档,可以考虑启动一个EXE程序,在其中使用学徒服务器去做。
Gotcha
Here’s something to watch out for when doing any timing tests like those above. The first time I ran a test it was slow and subsequent runs were significantly faster. For example, when I first ran test 2 with Inventor it took 100 seconds and then running the same test a second time only took 4 seconds. Even test 3, which doesn’t have anything to do with Inventor went from 77 seconds for the first run down to 0.338 seconds for subsequent runs. What’s happening is that Windows is caching data in memory in case the data is used again. This is great if you are reusing data but I think in most workflows where you’re batch reading and updating iProperties this won’t be the case. To get the times reported above I rebooted between each test to clear memory and force the data to be read from disk.
还有一点。以上的测试,第一次很慢,接着多次测试都会快些。例如测试2,Inventor API 第一次100秒,第二次只用了4秒。甚至测试3, 啥都没做,就从第一次的77秒到第二次的0.338秒。这是因为操作系统缓存了前面的数据,因此第二次访问就快了。因此如果你的流程中有重用数据的阶段,这是个好消息。

通过对比Inventor API与Apprentice服务器处理iProperties时的性能差异,本文揭示了不同应用场景下各自的优势。测试表明,对于大量文件的iProperties读写操作,Apprentice服务器提供了更快的速度,而在仅需读取的情况下,Inventor API通过隐式打开文档也能达到接近的速度。
1181

被折叠的 条评论
为什么被折叠?



