Skip to content

Commit

Permalink
Performance tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jamietre committed Mar 4, 2013
1 parent d0b7a86 commit fef9424
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><AddInEnabled>true</AddInEnabled></Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ static void Main()
{
PerformanceShared test = (PerformanceShared)Objects.CreateInstance(type);
test.LoadingDom();
//test.Miscellanous();
//test.IDSelectors();
//test.AttributeSelectors();
//test.SubSelectors();
//test.NthChild();
test.Miscellanous();
test.IDSelectors();
test.AttributeSelectors();
test.SubSelectors();
test.NthChild();
}

PerformanceTest.CleanupTestRun();
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery.PerformanceTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

8/8/2012

This is console application that runs a series of performance tests to compare CsQuery's performance with HtmlAgilityPack + Fizzler. It will produce output in an `output` subfolder of the current exe locaiton (or the project if running interactively).
This is console application that runs a series of performance tests to compare CsQuery's performance with HtmlAgilityPack + Fizzler. It will produce output in an `output` subfolder of the current exe location (or the project if running interactively).
7 changes: 3 additions & 4 deletions source/CsQuery/Dom/Implementation/DomElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,9 @@ public override IEnumerable<ushort[]> IndexKeysRanged()
{
output[i + 1] = path[i];
}
//Buffer.BlockCopy(path, 0, output, 2, path.Length * 2);

yield return output;

//yield return new ushort[] { HtmlData.indexSeparator }.Concat(path).ToArray();

yield return IndexKey('+',_NodeNameID, path);

string id = Id;
Expand Down Expand Up @@ -959,7 +956,9 @@ public override DomElement Clone()
{
clone.Style = Style.Clone();
}
// will not create ChildNodes lazy object unless results are returned (this is why we don't use AddRange)

// will not create ChildNodes lazy object unless results are returned (this is why we don't use
// AddRange)

var childNodes = (ChildNodeList)clone.ChildNodes;
foreach (IDomObject child in CloneChildren())
Expand Down
26 changes: 11 additions & 15 deletions source/CsQuery/Dom/Implementation/DomObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,45 +257,41 @@ protected virtual ushort[] GetPath_UnOptimized()

protected virtual ushort[] GetPath()
{


DomObject curNode = this;
ushort index = 0;

byte[] path = new byte[8];
int len = 8;
ushort[] path = new ushort[32];
int len = 32;

while (curNode != null)
{
path[index++] = (byte)(curNode.Index & 255);
path[index++] = (byte)(curNode.Index >> 8);
path[index++] = (ushort)(curNode.Index);

if (index == len)
{
len <<= 1;

var newPath = new byte[len];
Buffer.BlockCopy(path, 0, newPath, 0, index);
var newPath= new ushort[len];
Buffer.BlockCopy(path, 0, newPath, 0, index<<1);
path = newPath;
}

curNode = curNode._ParentNode;
}


//Array.Reverse(path, 0, index);
// because we obtained the path by traversing backards up the tree, instead of recursing (which
// will cause a stack overflow & performs a lot worse anyway) we must reverse the array before
// returning it.

//int olen = index>>1;
ushort[] output = new ushort[index>>1];
int j = 0;
ushort[] output = new ushort[index];
int i = 0;

while (index>0)
{
output[j++] = (ushort)((path[--index] << 8) + path[--index]);
output[i++] = path[--index];
}

// Buffer.BlockCopy(path, 0, output, 0, index);

return output;

}
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.3.3.397")]
[assembly: AssemblyVersion("1.3.3.403")]
//[assembly: AssemblyFileVersion("1.3.3")]

0 comments on commit fef9424

Please sign in to comment.