Inside MSXML Performance(MSXML效能分析) (4) (轉)
First Walk Working Set Delta:namespace prefix = o ns = "urn:schemas--com::office" />
第一次DOM樹遍歷引起的工作空間增量
Walking the DOM tree for the first time has an impact on the working set metric because some nodes in the tree are created on demand. To illustrate this, I'll show the working set deltas resulting from the first walk over the freshly loaded sample data:
在第一次遍歷DOM樹時,對工作空間這個度量指標會有一定的影響,因為樹中有些節點會被建立。為了說明這一點,這裡提供了首次遍歷載入的樣品資料時工作空間的增量:
Sample
樣品
Working set delta (percentage)
工作空間增量(百分比)
Ado.xml
0
Hamlet.xml
25
Ot.xml
14
Northwind.xml
36
According to these results, it seems that the ADO attribute case doesn't have any nodes created on demand.
以上結果顯示,ADO.xml在此時並不需要建立任何節點。
createNode Overhead
createNode的開銷
Creating a DOM tree from scratch results in a higher peak working set than loading the same document from disk. To illustrate this, I created a DOM document with 10,000 elements looking like this:
在記憶體中臨時建立一個DOM樹比從上載入同樣的文件會產生更高的工作空間峰值。為了說明這一點,這裡建立了一個DOM文件,包含10,000個相同的如下元素:
Then I compared the load time, load plus walk time (to force on-demand construction), and create time, showing associated working sets.
然後,比較載入時間,載入加遍歷時間(強制構造)和直接建立時間,下表顯示了相關的工作空間大小:
Function
功能
Time (milliseconds)
時間(單位為毫秒)
Working set (bytes)
工作空間(單位為位元組)
Load
146
842,137
Load+Walk
148
1,173,914
Create
740
2,503,066
These results show that loading a document is roughly five times faster than creating the same document from scratch in memory. The reason is that the process of creating a document requires a lot of DOM calls, which slows things down. Merely loading the document bypasses all this and goes directly to the internal data structures.
以上結果顯示載入一個文件比在記憶體中直接建立同樣的文件要快差不多5倍。原因是建立文件時需要有多次DOM,就會變慢。而載入文件就避開了這些,可以直接進入內部資料結構了。
Walk vs. SingleNode
遍歷與selectSingleNode
The fastest way to walk the tree is to avoid the children collection and any kind of array access. Instead, use firstChild and nextSibling:
最快遍歷樹的方法是避免子集合和任何陣列訪問。取而代之的,使用firstChild和nextSibling:
function WalkNodes(node)
{
var child = node.firstChild;
while (child != null)
{
WalkNodes(child);
child = child.nextSibling;
}
}
The following table shows the results for the sample test files—walking all elements, attributes, and text nodes:
以下表格顯示了樣本遍歷元素、屬性和文字節點的測試結果:
Sample
樣本
Walk time (milliseconds)
遍歷時間(毫秒)
Number of nodes
節點數量
Nodes/second
節點/秒
Ado.xml
243
63,723
262,234
Hamlet.xml
63
12,100
192,063
Ot.xml
660
118,720
179,878
Northwind.xml
33
6,438
195,090
However, if you are looking for something in the tree, a much faster way to find it is to use via the selectSingleNode or selectNodes methods. For example, I entered an XPath expression "//willnotfindanything", which walked the entire tree and got the following results that show the percentage improvement over a brute force tree walk:
但是,如果你要在樹中查詢某一事物,更快的方法是透過selectSingleNode或者selectNodes方法使用XPath進行查詢。例如,輸入一個XPath“//willnotfindanything”進行查詢,得到結果的顯示出同強制的樹的遍歷相比改進的百分比:
File
檔案
selectSingleNode (milliseconds)
selectSingleNode(毫秒)
Improvement (percentage)
改進(百分比)
Nodes/second
節點/秒
Ado.xml
173
29
368,341
Hamlet.xml
11
82
1,100,000
Ot.xml
113
82
1,050,619
Northwind.xml
5
84
1,287,600
selectSingleNode is faster because it avoids the overhead of calling through the layer. Instead of thousands of calls to firstChild and nextSibling, it works by one single call.
selectSingleNode更快是因為它避免了透過COM層呼叫的總開銷。它不必上千次呼叫firstChild和nextSibling,只需要一次呼叫就可以了。
Now, this comparison is really not equal: On one hand, selectSingleNode was doing less walking, because it didn't need to look at the text nodes—it could just skright over them. On the other hand, selectSingleNode was doing more work, because it was comparing each nodeName with the name specified in the query. But you get the a. In general, selectSingleNode reduces the amount of DOM code you need to write and gives you a noticeable performance improvement.
這個比較事實上並不恰當:一方面,selectSingleNode遍歷的開銷較少,因為它不需要檢視文字位元組,只需要跳過它們就可以了。而另一方面,selectSingleNode做了更多的工作,因為它要將查詢中指定的名字與每一個nodeName進行比較。但是你應該已經得到一些要點了。總的來說,selectSingleNode降低了你要寫的DOM程式碼,可以帶來顯著的提升。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-991689/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Inside MSXML Performance(MSXML效能分析) (轉)IDEXMLORM
- Inside MSXML Performance(MSXML效能分析) (2) (轉)IDEXMLORM
- Inside MSXML Performance(MSXML效能分析) (3) (轉)IDEXMLORM
- Inside MSXML Performance(MSXML效能分析) (6) (轉)IDEXMLORM
- Inside MSXML Performance(MSXML效能分析) (5) (轉)IDEXMLORM
- Inside MSXML Performance(MSXML效能分析) (7) (轉)IDEXMLORM
- MSXML4預覽版釋出 (轉)XML
- 使用window.performance分析頁面效能ORM
- 遊標指令碼效能問題解決與分析 (4) - Cursor Performance Analysis指令碼ORM
- 前端效能監控-window.performance(轉)前端ORM
- .NET Core 效能分析: xUnit.Performance 簡介ORM
- A Look Inside J2EE Patterns(4) (轉)IDE
- 【前端除錯】- 藉助Performance分析並最佳化效能前端除錯ORM
- Performance --- 前端效能監控ORM前端
- win10系統安裝office出現msxml6.10.1129.0錯誤的解決方法Win10XML
- oracle performance tunning(4)OracleORM
- 效能監視器- Performance MonitorORM
- 《Inside UE4》開篇IDE
- 《Inside UE4》目錄IDE
- 效能優化篇 - Performance(工具 & api)優化ORMAPI
- Win10電腦中玩帝國時代3遊戲提示未正確地安裝MSXML4.0怎麼解決Win10遊戲XML
- 遊標指令碼效能問題解決與分析 (2) - Cursor Performance Analysis指令碼ORM
- 《Inside UE4》基礎概念IDE
- Flutter效能監控工具(2)— Performance OverlayFlutterORM
- [轉] Android 效能分析案例Android
- inside sqlplus prelim(轉)IDESQL
- MySQL調優效能監控之performance schemaMySqlORM
- 初探 performance – 監控網頁與程式效能ORM網頁
- 【轉載】[效能分析]Oracle資料庫效能模型Oracle資料庫模型
- Linux 效能分析匯總(轉)Linux
- SQL Server效能分析引數 (轉)SQLServer
- Oracle Performance Tuning 11g2 (4)OracleORM
- 前端效能監測,Runtime Performance Debug 技巧前端ORM
- Tesla T4視訊編碼效能分析
- AIX 下磁碟 I/O 效能分析[轉]AI
- ( 轉)效能測試--地鐵模型分析模型
- AIX系統網路效能分析(轉)AI
- MySQL SQL Profiler效能分析器(轉)MySql