From c76856d73b96b0fb2684aabe93e5d12da9d32cee Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 22 May 2023 00:10:07 +0300 Subject: [PATCH 1/4] Added Convert.FromHex benchmark --- .../System.Runtime.Extensions/Perf.Convert.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs b/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs index c77f4eb778b..6ff99993161 100644 --- a/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs +++ b/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. @@ -18,6 +18,7 @@ public class Perf_Convert private byte[] _binaryData; private char[] _base64CharArray; private string _base64String; + private string _hexString; private char[] _base64Chars; [GlobalSetup(Target = nameof(GetTypeCode))] @@ -85,8 +86,16 @@ public void SetupToHexString() new Random(42).NextBytes(_binaryData); } + [GlobalSetup(Target = nameof(FromHexString))] + public void SetupFromHexString() + { + _hexString = Convert.ToHexString(Encoding.ASCII.GetBytes("This is a test of Convert.")); + } + [Benchmark] public string ToHexString() => Convert.ToHexString(_binaryData); + [Benchmark] + public byte[] FromHexString() => Convert.FromHexString(_hexString); #endif private static byte[] InitializeBinaryDataCollection(int size) From a177e01f2f35458980343ac6ae7e6cd40ed63c0d Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Sun, 21 May 2023 17:13:32 -0500 Subject: [PATCH 2/4] Update src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs --- .../micro/libraries/System.Runtime.Extensions/Perf.Convert.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs b/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs index 6ff99993161..235268ff56a 100644 --- a/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs +++ b/src/benchmarks/micro/libraries/System.Runtime.Extensions/Perf.Convert.cs @@ -18,7 +18,9 @@ public class Perf_Convert private byte[] _binaryData; private char[] _base64CharArray; private string _base64String; +#if NET5_0_OR_GREATER private string _hexString; +#endif private char[] _base64Chars; [GlobalSetup(Target = nameof(GetTypeCode))] From bf4d961c4a9e8f8937216f82e9d4d5a237c3da6c Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Mon, 22 May 2023 10:48:49 -0500 Subject: [PATCH 3/4] Robustify downloading dotnet --- scripts/dotnet.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/dotnet.py b/scripts/dotnet.py index 712aa71d727..745c6c6ac67 100755 --- a/scripts/dotnet.py +++ b/scripts/dotnet.py @@ -778,14 +778,14 @@ def install( # Download appropriate dotnet install script dotnetInstallScriptExtension = '.ps1' if platform == 'win32' else '.sh' dotnetInstallScriptName = 'dotnet-install' + dotnetInstallScriptExtension - url = 'https://dot.net/v1/' + url = 'https://dot.net/v1/' dotnetInstallScriptUrl = url + dotnetInstallScriptName dotnetInstallScriptPath = path.join(install_dir, dotnetInstallScriptName) getLogger().info('Downloading %s', dotnetInstallScriptUrl) count = 0 - while count < 3: + while count < 5: try: with urlopen(dotnetInstallScriptUrl, context=ssl._create_unverified_context()) as response: if "html" in response.info()['Content-Type']: @@ -795,12 +795,13 @@ def install( with open(dotnetInstallScriptPath, 'wb') as outfile: outfile.write(response.read()) break - except Exception: + except Exception as error: + getLogger().warning(f"Could not download dotnet-install script from {dotnetInstallScriptUrl}; Reason: {error.reason}; Attempt {count}") count = count + 1 - sleep(1) + sleep(count ** 2) continue - if count == 3: + if count == 5: getLogger().error("Fatal error: could not download dotnet-install script") raise Exception("Fatal error: could not download dotnet-install script") From fe3f7faaedcbdd603b531ac0861bf621c734c928 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Mon, 22 May 2023 11:00:03 -0500 Subject: [PATCH 4/4] more --- scripts/dotnet.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/dotnet.py b/scripts/dotnet.py index 745c6c6ac67..cac3014875f 100755 --- a/scripts/dotnet.py +++ b/scripts/dotnet.py @@ -785,23 +785,31 @@ def install( getLogger().info('Downloading %s', dotnetInstallScriptUrl) count = 0 - while count < 5: + max_count = 10 + while count < max_count: try: with urlopen(dotnetInstallScriptUrl, context=ssl._create_unverified_context()) as response: if "html" in response.info()['Content-Type']: count = count + 1 - sleep(1) # sleep one second + sleep(count ** 2) continue with open(dotnetInstallScriptPath, 'wb') as outfile: outfile.write(response.read()) break + except URLError as error: + getLogger().warning(f"Could not download dotnet-install script from {dotnetInstallScriptUrl}; {Reason: {error.reason}}; Attempt {count}") + count = count + 1 + sleep(count ** 2) + continue except Exception as error: - getLogger().warning(f"Could not download dotnet-install script from {dotnetInstallScriptUrl}; Reason: {error.reason}; Attempt {count}") + getLogger().warning(f"Could not download dotnet-install script from {dotnetInstallScriptUrl}; {type(error).__name__}; Attempt {count}") count = count + 1 sleep(count ** 2) continue - if count == 5: + getLogger().info(f"Downloaded {dotnetInstallScriptUrl} OK") + + if count == max_count: getLogger().error("Fatal error: could not download dotnet-install script") raise Exception("Fatal error: could not download dotnet-install script")