Skip to content

Commit 7484488

Browse files
Add UpdateStats task
1 parent fbc0d7f commit 7484488

File tree

3 files changed

+86
-14
lines changed

3 files changed

+86
-14
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It's no harder than writing unit tests!
3030
Under the hood, it performs a lot of [magic](#automation) that guarantees [reliable and precise](#reliability) results thanks to the [perfolizer](https://github.com/AndreyAkinshin/perfolizer) statistical engine.
3131
BenchmarkDotNet protects you from popular benchmarking mistakes and warns you if something is wrong with your benchmark design or obtained measurements.
3232
The results are presented in a [user-friendly](#friendliness) form that highlights all the important facts about your experiment.
33-
The library is adopted by [14300+ projects](#who-uses-benchmarkdotnet) including .NET Runtime and supported by the [.NET Foundation](https://dotnetfoundation.org).
33+
The library is adopted by [16500+ GitHub projects](#who-uses-benchmarkdotnet) including .NET Runtime and supported by the [.NET Foundation](https://dotnetfoundation.org).
3434

3535
It's [easy](#simplicity) to start writing benchmarks, check out an example
3636
(copy-pastable version is [here](https://benchmarkdotnet.org/articles/guides/getting-started.html)):
@@ -232,7 +232,7 @@ If you don't customize the summary view,
232232
## Who uses BenchmarkDotNet?
233233

234234
Everyone!
235-
BenchmarkDotNet is already adopted by more than [14300+](https://github.com/dotnet/BenchmarkDotNet/network/dependents?package_id=UGFja2FnZS0xNTY3MzExMzE%3D) projects including
235+
BenchmarkDotNet is already adopted by more than [16500+](https://github.com/dotnet/BenchmarkDotNet/network/dependents?package_id=UGFja2FnZS0xNTY3MzExMzE%3D) projects including
236236
[dotnet/performance](https://github.com/dotnet/performance) (reference benchmarks for all .NET Runtimes),
237237
[dotnet/runtime](https://github.com/dotnet/runtime/issues?utf8=%E2%9C%93&q=BenchmarkDotNet) (.NET runtime and libraries),
238238
[Roslyn](https://github.com/dotnet/roslyn/search?q=BenchmarkDotNet&type=Issues&utf8=✓) (C# and Visual Basic compiler),
@@ -266,11 +266,6 @@ BenchmarkDotNet is already adopted by more than [14300+](https://github.com/dotn
266266
[MediatR](https://github.com/jbogard/MediatR/tree/master/test/MediatR.Benchmarks),
267267
[TensorFlow.NET](https://github.com/SciSharp/TensorFlow.NET/tree/master/src/TensorFlowNet.Benchmarks),
268268
[Apache Thrift](https://github.com/apache/thrift/tree/master/lib/netstd/Benchmarks/Thrift.Benchmarks).
269-
On GitHub, you can find
270-
12600+ [issues](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=created&type=Issues&utf8=✓),
271-
5200+ [commits](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=committer-date&type=Commits&utf8=✓), and
272-
1,600,000+ [files](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=indexed&type=Code&utf8=✓)
273-
that involve BenchmarkDotNet.
274269

275270
## Learn more about benchmarking
276271

build/Program.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Net.Http;
45
using System.Text;
6+
using System.Text.RegularExpressions;
7+
using System.Threading.Tasks;
58
using Build;
69
using Cake.Common;
710
using Cake.Common.Build;
@@ -570,3 +573,82 @@ public override void Run(BuildContext context)
570573
context.GenerateRedirects();
571574
}
572575
}
576+
577+
[TaskName("UpdateStats")]
578+
public class UpdateStatsTask : FrostingTask<BuildContext>
579+
{
580+
public class Updater
581+
{
582+
public string Prefix { get; }
583+
public Regex Regex { get; }
584+
public int Value { get; }
585+
586+
public Updater(string prefix, string regex, int value)
587+
{
588+
Prefix = prefix;
589+
Regex = new Regex(regex);
590+
Value = value;
591+
}
592+
593+
public string Apply(string line)
594+
{
595+
if (!line.StartsWith(Prefix))
596+
return line;
597+
598+
var match = Regex.Match(line);
599+
if (!match.Success)
600+
return line;
601+
602+
// Groups[1] refers to the first group (\d+)
603+
var numberString = match.Groups[1].Value;
604+
var number = int.Parse(numberString);
605+
return line.Replace(number.ToString(), Value.ToString());
606+
}
607+
}
608+
609+
private static async Task<int> GetDependentProjectsNumber()
610+
{
611+
using var httpClient = new HttpClient();
612+
const string url = "https://github.com/dotnet/BenchmarkDotNet/network/dependents";
613+
var response = await httpClient.GetAsync(new Uri(url));
614+
var dependentsPage = await response.Content.ReadAsStringAsync();
615+
var match = new Regex(@"([0-9\,]+)[\n\r\s]+Repositories").Match(dependentsPage);
616+
var number = int.Parse(match.Groups[1].Value.Replace(",", ""));
617+
number = number / 100 * 100;
618+
return number;
619+
}
620+
621+
public override void Run(BuildContext context)
622+
{
623+
var dependentProjectsNumber = GetDependentProjectsNumber().Result;
624+
var updaters = new Updater[]
625+
{
626+
new(
627+
"The library is adopted by",
628+
@"\[(\d+)\+ GitHub projects\]",
629+
dependentProjectsNumber
630+
),
631+
new(
632+
"BenchmarkDotNet is already adopted by more than ",
633+
@"\[(\d+)\+\]",
634+
dependentProjectsNumber
635+
),
636+
};
637+
var files = new[]
638+
{
639+
context.RootDirectory.CombineWithFilePath("README.md"),
640+
context.DocsDirectory.CombineWithFilePath("index.md")
641+
};
642+
foreach (var file in files)
643+
{
644+
var lines = context.FileReadLines(file);
645+
for (var i = 0; i < lines.Length; i++)
646+
{
647+
foreach (var updater in updaters)
648+
lines[i] = updater.Apply(lines[i]);
649+
}
650+
651+
context.FileWriteLines(file, lines);
652+
}
653+
}
654+
}

docs/index.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ It's no harder than writing unit tests!
3434
Under the hood, it performs a lot of [magic](#automation) that guarantees [reliable and precise](#reliability) results thanks to the [perfolizer](https://github.com/AndreyAkinshin/perfolizer) statistical engine.
3535
BenchmarkDotNet protects you from popular benchmarking mistakes and warns you if something is wrong with your benchmark design or obtained measurements.
3636
The results are presented in a [user-friendly](#friendliness) form that highlights all the important facts about your experiment.
37-
The library is adopted by [14300+ projects](#who-uses-benchmarkdotnet) including .NET Runtime and supported by the [.NET Foundation](https://dotnetfoundation.org).
37+
The library is adopted by [16500+ GitHub projects](#who-uses-benchmarkdotnet) including .NET Runtime and supported by the [.NET Foundation](https://dotnetfoundation.org).
3838

3939
It's [easy](#simplicity) to start writing benchmarks, check out an example
4040
(copy-pastable version is [here](https://benchmarkdotnet.org/articles/guides/getting-started.html)):
@@ -236,7 +236,7 @@ If you don't customize the summary view,
236236
## Who uses BenchmarkDotNet?
237237

238238
Everyone!
239-
BenchmarkDotNet is already adopted by more than [14300+](https://github.com/dotnet/BenchmarkDotNet/network/dependents?package_id=UGFja2FnZS0xNTY3MzExMzE%3D) projects including
239+
BenchmarkDotNet is already adopted by more than [16500+](https://github.com/dotnet/BenchmarkDotNet/network/dependents?package_id=UGFja2FnZS0xNTY3MzExMzE%3D) projects including
240240
[dotnet/performance](https://github.com/dotnet/performance) (reference benchmarks for all .NET Runtimes),
241241
[dotnet/runtime](https://github.com/dotnet/runtime/issues?utf8=%E2%9C%93&q=BenchmarkDotNet) (.NET runtime and libraries),
242242
[Roslyn](https://github.com/dotnet/roslyn/search?q=BenchmarkDotNet&type=Issues&utf8=✓) (C# and Visual Basic compiler),
@@ -270,11 +270,6 @@ BenchmarkDotNet is already adopted by more than [14300+](https://github.com/dotn
270270
[MediatR](https://github.com/jbogard/MediatR/tree/master/test/MediatR.Benchmarks),
271271
[TensorFlow.NET](https://github.com/SciSharp/TensorFlow.NET/tree/master/src/TensorFlowNet.Benchmarks),
272272
[Apache Thrift](https://github.com/apache/thrift/tree/master/lib/netstd/Benchmarks/Thrift.Benchmarks).
273-
On GitHub, you can find
274-
12600+ [issues](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=created&type=Issues&utf8=✓),
275-
5200+ [commits](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=committer-date&type=Commits&utf8=✓), and
276-
1,600,000+ [files](https://github.com/search?o=desc&q=BenchmarkDotNet+-repo:dotnet%2FBenchmarkDotNet&s=indexed&type=Code&utf8=✓)
277-
that involve BenchmarkDotNet.
278273

279274
## Learn more about benchmarking
280275

0 commit comments

Comments
 (0)