Skip to content

Commit

Permalink
Merge pull request #6 from JosepeDev/v0_9_0
Browse files Browse the repository at this point in the history
Version 0_9_0
  • Loading branch information
jozzzzep authored Dec 16, 2020
2 parents 82c7383 + 3240d95 commit 8f475a2
Show file tree
Hide file tree
Showing 23 changed files with 885 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
public TypeInBenchmark benchmark1;
public TypeInBenchmark benchmark2;

public bool IsValid
{
get =>
changesAmount > 0 &&
testsAmount > 0 &&
!string.IsNullOrEmpty(benchmarkPresetGroupName) &&
benchmark1 != null &&
benchmark2 != null;
}

public BenchmarkData(TypeInBenchmark _benchmark1, TypeInBenchmark _benchmark2, int _howMuchToIncrement, int _testsAmount)
{
changesAmount = _howMuchToIncrement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,30 @@ public static class BenchmarksManager
new TypeInBenchmark("EncString (0.6.0)", WL_EncString_0_6_0),
new TypeInBenchmark("EncInt (0.3.0)", WL_EncInt_0_3_0), // 14
new TypeInBenchmark("EncInt (0.7.0)", WL_EncInt_0_7_0),
new TypeInBenchmark("EncDouble (0.5.0)", WL_EncDouble_0_5_0), // 16
new TypeInBenchmark("EncDouble (0.7.0)", WL_EncDouble_0_7_0),
new TypeInBenchmark("EncInt (0.8.0)", WL_EncInt_0_8_0), // 16
new TypeInBenchmark("EncDouble (0.5.0)", WL_EncDouble_0_5_0),
new TypeInBenchmark("EncDouble (0.7.0)", WL_EncDouble_0_7_0), // 18
new TypeInBenchmark("EncDouble (0.8.0)", WL_EncDouble_0_8_0),
new TypeInBenchmark("EncString (0.8.0)", WL_EncString_0_8_0), // 20
};

static public BenchmarkData[] comparisons =
{
new BenchmarkData(benchmarkTypes[0], benchmarkTypes[1]),
new BenchmarkData(benchmarkTypes[0], benchmarkTypes[14]),
new BenchmarkData(benchmarkTypes[0], benchmarkTypes[15]),
new BenchmarkData(benchmarkTypes[0], benchmarkTypes[16]),
new BenchmarkData(benchmarkTypes[2], benchmarkTypes[3]),
new BenchmarkData(benchmarkTypes[4], benchmarkTypes[5]),
new BenchmarkData(benchmarkTypes[6], benchmarkTypes[7]),
new BenchmarkData(benchmarkTypes[6], benchmarkTypes[16]),
new BenchmarkData(benchmarkTypes[6], benchmarkTypes[17]),
new BenchmarkData(benchmarkTypes[6], benchmarkTypes[18]),
new BenchmarkData(benchmarkTypes[6], benchmarkTypes[19]),
new BenchmarkData(benchmarkTypes[8], benchmarkTypes[9]),
new BenchmarkData(benchmarkTypes[10], benchmarkTypes[11]),
new BenchmarkData(benchmarkTypes[10], benchmarkTypes[12]),
new BenchmarkData(benchmarkTypes[10], benchmarkTypes[13]),
new BenchmarkData(benchmarkTypes[10], benchmarkTypes[20]),
};

static BenchmarkPreset[] benchmarkPresetsFastest =
Expand Down Expand Up @@ -116,7 +122,7 @@ public static class BenchmarksManager
new BenchmarkPresetGroup("Very Long", benchmarkPresetsVeryLong),
};

public static void RunBenchmarks(BenchmarkData benchmarkData)
public static void RunBenchmark(BenchmarkData benchmarkData)
{
Console.Clear();

Expand Down Expand Up @@ -214,11 +220,20 @@ static void AfterBenchmark()
SeparationLineSmall();
WriteLines(afterBenchmarkLines);
SeparationLineSmall();
WriteLine("Press Space to run again the same benchmark");
WriteLine("Press any key to return to the menu");
SeparationLine();
currentBenchmarkResults = null;
Console.ReadKey();
MenuSystem.StartProgram();

var k = Console.ReadKey();
if (k.Key == ConsoleKey.Spacebar)
{
RunBenchmark(MenuSystem.currentBenchmarkData);
}
else
{
MenuSystem.StartProgram();
}
}

static double ChangesPerSecond(int changes, double seconds) => (changes / seconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,37 @@

static class MenuSystem
{
static string currentVersion = "- Current version - 0.9.0";
static string titleOfApplication = "VarEnc's Benchmarking Console Application";
static ChoosingState currentState;
static BenchmarkData currentBenchmarkData;
public static BenchmarkData currentBenchmarkData;
static BenchmarkPresetGroup currentBenchmarkPresetGroup;
static private string choiceText = "Type the number of your choice and press ENTER";

static private string[] sectionsTitle =
{
"Step #1: VARIABLE TYPE",
"Step #1: TYPES TO COMPARE",
"Step #2: BENCHMARK DURATION",
"Step #3: BENCHMARK PRESET"
};

static string[] SectionText(int stepNum)
{
string[] textToReturn;
string previousBenchmarkText =
(currentBenchmarkData == null || !currentBenchmarkData.IsValid)
? ""
: "\n - Type the letter \"p\" or the word \"prev\" to see the size of each type in bytes.";

switch (stepNum)
{
case 0:
string[] text1 =
{
"- Current version - 0.8.0",
currentVersion,
"- Welcome to the console app for speedtesting the VarEnc features.",
"- If you already know the numbers of your choices, you can input them all together. (separated with spaces)",
"- Type the letter \"s\" or the word \"size\" to see the size of each type in bytes.",
"- Type the letter \"s\" or the word \"size\" to see the size of each type in bytes." + previousBenchmarkText,
"- These are the types you can compare:"
};
textToReturn = text1;
Expand All @@ -39,7 +45,6 @@ static string[] SectionText(int stepNum)
{
string.Format("You chose to compare the types {0} and {1}", currentBenchmarkData.benchmark1.typeName, currentBenchmarkData.benchmark2.typeName),
"Now choose how long you want the benchmark to be.",
"Be aware that the \"Fastest\" benchmarks are the least accurate."
};
textToReturn = text2;
break;
Expand Down Expand Up @@ -194,11 +199,16 @@ public static void GetInputForNextSection(int sectionNum)
PrintSizesOfTypes();
}

// input for seeing the sizes of the types
else if (currentState == ChoosingState.ChoosingComparisons && line.Contains("p") && currentBenchmarkData != null && currentBenchmarkData.IsValid)
{
BenchmarksManager.RunBenchmark(currentBenchmarkData);
}

// input for benchmark
else
{
int indexOfFirstSpace = line.IndexOf(' ');
if (line.Contains(" ") && indexOfFirstSpace != (line.Length - 1) && Char.IsDigit(line[indexOfFirstSpace + 1]) && Char.IsDigit(line[indexOfFirstSpace - 1]))
if (line.Contains(" ") && ContainingDigits(line))
{
string[] entries = line.Split(' ');
List<int> e = new List<int>();
Expand Down Expand Up @@ -235,7 +245,6 @@ public static void GetInputForNextSection(int sectionNum)
public static void StartProgram()
{
Console.Title = titleOfApplication;
currentBenchmarkData = null;
currentState = ChoosingState.ChoosingComparisons;
PrintSection(0);
}
Expand Down Expand Up @@ -289,7 +298,7 @@ public static void AddDataFromInput(int sectionNum, int input, bool printAfter =
case 2:
currentState = ChoosingState.Complete;
currentBenchmarkData.InputPreset(currentBenchmarkPresetGroup.presets[inputForArray], currentBenchmarkPresetGroup.Name, input);
BenchmarksManager.RunBenchmarks(currentBenchmarkData);
BenchmarksManager.RunBenchmark(currentBenchmarkData);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public static void WL_EncInt_0_7_0(int amount)
}
}

public static void WL_EncInt_0_8_0(int amount)
{
EncInt_0_8_0 number1 = 0;
while (number1 < amount)
{
number1++;
}
}

public static void WL_Long(int amount)
{
long number1 = 0;
Expand Down Expand Up @@ -140,6 +149,17 @@ public static void WL_EncDouble_0_7_0(int amount)
}
}

public static void WL_EncDouble_0_8_0(int amount)
{
EncDouble_0_8_0 number1 = RandomDouble();
int timesIncremented = 0;
while (timesIncremented < amount)
{
number1 += 0.46772781036222716d;
timesIncremented++;
}
}

public static void WL_Decimal(int amount)
{
decimal number1 = (decimal)RandomDouble() + 1.467727810362227164677278103622271646772781036222716m;
Expand Down Expand Up @@ -230,5 +250,22 @@ public static void WL_EncString_0_6_0(int amount)
}
}

public static void WL_EncString_0_8_0(int amount)
{
EncString_0_8_0 stringVar = RandomString();
int currentPos = 0;
int timesIncremented = 0;
while (timesIncremented < amount)
{
timesIncremented++;
stringVar = StringReplaceAt(stringVar, currentPos, RandomCharNormal());
currentPos++;
if (currentPos >= stringVar.Length)
{
currentPos = 0;
}
}
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public static int GetTheHighestLength(string[] sr)

public static bool ContainingOnlyDigits(string s)
{
if (string.IsNullOrWhiteSpace(s)) return false;
for (int i = 0; i < s.Length; i++)
{
if (!Char.IsDigit(s[i]))
Expand All @@ -187,6 +188,19 @@ public static bool ContainingOnlyDigits(string s)
return true;
}

public static bool ContainingDigits(string s)
{
if (string.IsNullOrWhiteSpace(s)) return false;
for (int i = 0; i < s.Length; i++)
{
if (Char.IsDigit(s[i]))
{
return true;
}
}
return false;
}

public static int GetSize(Type t)
{
return System.Runtime.InteropServices.Marshal.SizeOf(t);
Expand Down
Loading

0 comments on commit 8f475a2

Please sign in to comment.