This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14095 from JosephTremoulet/BenchmarksGame/2.0.0
Port BenchmarksGame updates to release/2.0.0
- Loading branch information
Showing
57 changed files
with
3,929 additions
and
1,973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees-2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// Adapted from binary-trees C# .NET Core #2 program | ||
// http://benchmarksgame.alioth.debian.org/u64q/program.php?test=binarytrees&lang=csharpcore&id=2 | ||
// aka (as of 2017-09-01) rev 1.3 of https://alioth.debian.org/scm/viewvc.php/benchmarksgame/bench/binarytrees/binarytrees.csharp-2.csharp?root=benchmarksgame&view=log | ||
// Best-scoring single-threaded C# .NET Core version as of 2017-09-01 | ||
|
||
/* The Computer Language Benchmarks Game | ||
http://benchmarksgame.alioth.debian.org/ | ||
contributed by Marek Safar | ||
*reset* | ||
*/ | ||
|
||
using System; | ||
using Microsoft.Xunit.Performance; | ||
|
||
[assembly: OptimizeForBenchmarks] | ||
[assembly: MeasureGCCounts] | ||
|
||
namespace BenchmarksGame | ||
{ | ||
public class BinaryTrees_2 | ||
{ | ||
const int minDepth = 4; | ||
|
||
public static int Main(String[] args) | ||
{ | ||
int n = 0; | ||
if (args.Length > 0) n = Int32.Parse(args[0]); | ||
|
||
int check = Bench(n, true); | ||
int expected = 4398; | ||
|
||
// Return 100 on success, anything else on failure. | ||
return check - expected + 100; | ||
} | ||
|
||
[Benchmark(InnerIterationCount = 7)] | ||
public static void RunBench() | ||
{ | ||
Benchmark.Iterate(() => Bench(16, false)); | ||
} | ||
|
||
static int Bench(int n, bool verbose) | ||
{ | ||
int maxDepth = Math.Max(minDepth + 2, n); | ||
int stretchDepth = maxDepth + 1; | ||
|
||
int check = (TreeNode.bottomUpTree(stretchDepth)).itemCheck(); | ||
int checkSum = check; | ||
if (verbose) Console.WriteLine("stretch tree of depth {0}\t check: {1}", stretchDepth, check); | ||
|
||
TreeNode longLivedTree = TreeNode.bottomUpTree(maxDepth); | ||
|
||
for (int depth = minDepth; depth <= maxDepth; depth += 2) | ||
{ | ||
int iterations = 1 << (maxDepth - depth + minDepth); | ||
|
||
check = 0; | ||
for (int i = 1; i <= iterations; i++) | ||
{ | ||
check += (TreeNode.bottomUpTree(depth)).itemCheck(); | ||
} | ||
checkSum += check; | ||
|
||
if (verbose) | ||
Console.WriteLine("{0}\t trees of depth {1}\t check: {2}", iterations, depth, check); | ||
} | ||
|
||
check = longLivedTree.itemCheck(); | ||
checkSum += check; | ||
|
||
if (verbose) | ||
Console.WriteLine("long lived tree of depth {0}\t check: {1}", maxDepth, check); | ||
|
||
return checkSum; | ||
} | ||
|
||
|
||
struct TreeNode | ||
{ | ||
class Next | ||
{ | ||
public TreeNode left, right; | ||
} | ||
|
||
private Next next; | ||
|
||
internal static TreeNode bottomUpTree(int depth) | ||
{ | ||
if (depth > 0) | ||
{ | ||
return new TreeNode( | ||
bottomUpTree(depth - 1) | ||
, bottomUpTree(depth - 1) | ||
); | ||
} | ||
else | ||
{ | ||
return new TreeNode(); | ||
} | ||
} | ||
|
||
TreeNode(TreeNode left, TreeNode right) | ||
{ | ||
this.next = new Next(); | ||
this.next.left = left; | ||
this.next.right = right; | ||
} | ||
|
||
internal int itemCheck() | ||
{ | ||
// if necessary deallocate here | ||
if (next == null) return 1; | ||
else return 1 + next.left.itemCheck() + next.right.itemCheck(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees-5.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// Adapted from binary-trees C# .NET Core #5 program | ||
// http://benchmarksgame.alioth.debian.org/u64q/program.php?test=binarytrees&lang=csharpcore&id=5 | ||
// aka (as of 2017-09-01) rev 1.1 of https://alioth.debian.org/scm/viewvc.php/benchmarksgame/bench/binarytrees/binarytrees.csharp-5.csharp?root=benchmarksgame&view=log | ||
// Best-scoring C# .NET Core version as of 2017-09-01 | ||
|
||
/* The Computer Language Benchmarks Game | ||
http://benchmarksgame.alioth.debian.org/ | ||
contributed by Marek Safar | ||
*reset* | ||
concurrency added by Peperud | ||
minor improvements by Alex Yakunin | ||
*/ | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Microsoft.Xunit.Performance; | ||
|
||
[assembly: OptimizeForBenchmarks] | ||
[assembly: MeasureGCCounts] | ||
|
||
namespace BenchmarksGame | ||
{ | ||
public sealed class BinaryTrees_5 | ||
{ | ||
public const int MinDepth = 4; | ||
|
||
public static int Main(string[] args) | ||
{ | ||
var n = args.Length == 0 ? 0 : int.Parse(args[0]); | ||
|
||
int check = Bench(n, true); | ||
int expected = 4398; | ||
|
||
// Return 100 on success, anything else on failure. | ||
return check - expected + 100; | ||
} | ||
|
||
[Benchmark(InnerIterationCount = 7)] | ||
public static void RunBench() | ||
{ | ||
Benchmark.Iterate(() => Bench(16, false)); | ||
} | ||
|
||
static int Bench(int n, bool verbose) | ||
{ | ||
var maxDepth = n < (MinDepth + 2) ? MinDepth + 2 : n; | ||
var stretchDepth = maxDepth + 1; | ||
|
||
var stretchDepthTask = Task.Run(() => TreeNode.CreateTree(stretchDepth).CountNodes()); | ||
var maxDepthTask = Task.Run(() => TreeNode.CreateTree(maxDepth).CountNodes()); | ||
|
||
var tasks = new Task<string>[(maxDepth - MinDepth) / 2 + 1]; | ||
for (int depth = MinDepth, ti = 0; depth <= maxDepth; depth += 2, ti++) | ||
{ | ||
var iterationCount = 1 << (maxDepth - depth + MinDepth); | ||
var depthCopy = depth; // To make sure closure value doesn't change | ||
tasks[ti] = Task.Run(() => | ||
{ | ||
var count = 0; | ||
if (depthCopy >= 17) | ||
{ | ||
// Parallelized computation for relatively large tasks | ||
var miniTasks = new Task<int>[iterationCount]; | ||
for (var i = 0; i < iterationCount; i++) | ||
miniTasks[i] = Task.Run(() => TreeNode.CreateTree(depthCopy).CountNodes()); | ||
Task.WaitAll(miniTasks); | ||
for (var i = 0; i < iterationCount; i++) | ||
count += miniTasks[i].Result; | ||
} | ||
else | ||
{ | ||
// Sequential computation for smaller tasks | ||
for (var i = 0; i < iterationCount; i++) | ||
count += TreeNode.CreateTree(depthCopy).CountNodes(); | ||
} | ||
return $"{iterationCount}\t trees of depth {depthCopy}\t check: {count}"; | ||
}); | ||
} | ||
Task.WaitAll(tasks); | ||
|
||
if (verbose) | ||
{ | ||
int count = 0; | ||
Action<string> printAndSum = (string s) => | ||
{ | ||
Console.WriteLine(s); | ||
count += int.Parse(s.Substring(s.LastIndexOf(':') + 1).TrimStart()); | ||
}; | ||
|
||
printAndSum(String.Format("stretch tree of depth {0}\t check: {1}", | ||
stretchDepth, stretchDepthTask.Result)); | ||
foreach (var task in tasks) | ||
printAndSum(task.Result); | ||
printAndSum(String.Format("long lived tree of depth {0}\t check: {1}", | ||
maxDepth, maxDepthTask.Result)); | ||
|
||
return count; | ||
} | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
public struct TreeNode | ||
{ | ||
public sealed class NodeData | ||
{ | ||
public TreeNode Left, Right; | ||
|
||
public NodeData(TreeNode left, TreeNode right) | ||
{ | ||
Left = left; | ||
Right = right; | ||
} | ||
} | ||
|
||
public NodeData Data; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public TreeNode(TreeNode left, TreeNode right) | ||
{ | ||
Data = new NodeData(left, right); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static TreeNode CreateTree(int depth) | ||
{ | ||
return depth <= 0 | ||
? default(TreeNode) | ||
: new TreeNode(CreateTree(depth - 1), CreateTree(depth - 1)); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public int CountNodes() | ||
{ | ||
if (ReferenceEquals(Data, null)) | ||
return 1; | ||
return 1 + Data.Left.CountNodes() + Data.Right.CountNodes(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.