使用Java 2.11版本。我正在基于CD Catalog数据绑定示例构建xml绑定组件。我有一个相当复杂但相当小的doc 2000字节。而且AutoPilot.bind()似乎很慢…
int count = 10000; long start = System.nanoTime(); for(int i = 0; i <= count; i++) { //Init VTDGen, VTGNav here... AutoPilot ap0 = new Autopilot(); AutoPilot ap1 = new Autopilot(); AutoPilot ap2 = new Autopilot(); AutoPilot ap3 = new Autopilot(); AutoPilot ap4 = new Autopilot(); // Set the XPAth for auto pilots here... // Read bytes and parse... // Bind autopilot to NAV. MyObj mine = new MyObj(); // Do data binding here to My Object here... } long end = System.nanoTime(); long avgTime = (end - start) / count;
硬件= 3GH 8核心英特尔
平均解析时间约为80000纳秒。
现在,如果将自动驾驶仪的创建移出循环,则平均解析时间为10000纳秒。
当然,这在这里是行得通的,因为我们要反复分析同一文档。现在描述一个服务器场景,例如servlet,其中每个请求都解析接收到的XML文档是什么。如果我们可以重用自动驾驶而不是创建一个新的自动驾驶,那就太好了。
我记得在某个地方读过一些文章,以创建一个自动驾驶仪库,但这没什么好玩的,尤其是当您有十几个自动驾驶仪时。