From 73ba086c54d7b2a3dce4bfe86fee1a204578f1d7 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Wed, 14 Aug 2024 21:46:36 +0200 Subject: [PATCH] added testing + some performance improvements --- BeefProj.toml | 1 - BeefSpace.toml | 4 ++ src/BofaParser.bf | 10 +++- src/Program.bf | 39 ++++++++++++++ src/Testing/Profiling.bf | 110 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 src/Program.bf diff --git a/BeefProj.toml b/BeefProj.toml index 0d15fdc..ddfd45a 100644 --- a/BeefProj.toml +++ b/BeefProj.toml @@ -2,5 +2,4 @@ FileVersion = 1 [Project] Name = "Bofa" -TargetType = "BeefLib" StartupObject = "Bofa.Program" diff --git a/BeefSpace.toml b/BeefSpace.toml index ba54fc1..9edf396 100644 --- a/BeefSpace.toml +++ b/BeefSpace.toml @@ -6,3 +6,7 @@ StartupProject = "Bofa" [Configs.Test.Win64] LargeStrings = true + +[Configs.Debug.Win64] +LargeStrings = true +LargeCollections = true diff --git a/src/BofaParser.bf b/src/BofaParser.bf index 85b36d8..6de49d2 100644 --- a/src/BofaParser.bf +++ b/src/BofaParser.bf @@ -2,6 +2,7 @@ namespace Bofa; using System; using System.IO; +using System.Security.Cryptography; using System.Collections; using Bofa.Parser; @@ -17,6 +18,10 @@ class BofaParser public static void Parse(Stream pToParse, List pResult, List pErrors) { + HashSet lowLevelObjects = new .(100); + defer delete lowLevelObjects; + + if (pToParse == null || pResult == null) { //Cannot parse what doesnt exist pErrors.Add(-1); @@ -52,8 +57,10 @@ class BofaParser //If we are on the lowest level we can just add them here if(entry.Depth == 0 && entry.Type ==.Bofa) { - if(pResult.FindIndex(scope (x) => { return x.Name == entry.Data.Bofa.Name;}) < 0) + if(lowLevelObjects.Add(SHA256.Hash(cast!>(entry.Data.Bofa.Name)))) + { pResult.Add(entry.Data.Bofa); + } else { pErrors.Add(entry.Line); //Dublicate name error @@ -305,4 +312,5 @@ class BofaParser } return (.(pLine, 0, (i < pLine.Length) ? i - 1 : i), .(pLine, i)); } + } \ No newline at end of file diff --git a/src/Program.bf b/src/Program.bf new file mode 100644 index 0000000..efd7a93 --- /dev/null +++ b/src/Program.bf @@ -0,0 +1,39 @@ +using System; + +namespace Bofa +{ + + class Program + { + public static void Main() + { + Bofa.Testing.Profiling.Profiling_Normal_Large(); + } + } +} + + + +namespace System.Security.Cryptography +{ + extension SHA256Hash : IHashable + { + public int GetHashCode() + { + return this.mHash[0]; + } + } + + +} + +namespace System +{ + static + { + public static mixin cast(var v) + { + *(T*)(void*)&v + } + } +} \ No newline at end of file diff --git a/src/Testing/Profiling.bf b/src/Testing/Profiling.bf index 1ace203..265aba2 100644 --- a/src/Testing/Profiling.bf +++ b/src/Testing/Profiling.bf @@ -1,5 +1,115 @@ namespace Bofa.Testing; +using Bofa; + +using System; +using System.Collections; + class Profiling { + [Test(Name = "Profiling: normal 1000 * 15")] + public static void Profiling_Normal() + { + for (int i < 1000) + { + String content = """ + l one line of text + b bool true + # saoidsaodsad + t text goes here + - Text addendum + n tone 12.5 + #husdhfiudshfds + bn biggie 65645645645.6 + i int 234345 + + + bi bint 38432847329847329 + o object + b content true + a array + b content true + b content true + """; + List output = new .(); + List errors = new .(); + BofaParser.Parse(content, output, errors); + DeleteContainerAndItems!(output); + delete errors; + } + } + + [Test(Name = "Profiling: normal 10 * 1500")] + public static void Profiling_Normal_Medium() + { + for (int i < 10) + { + String toParse = new .(10 * 1500); + for (int ii < 100) + { + toParse.Append(scope $""" + l one{ii} line of text + b bool{ii} true + # saoidsaodsad + t text{ii} goes here + - Text addendum + n tone{ii} 12.5 + #husdhfiudshfds + bn biggie{ii} 65645645645.6 + i int{ii} 234345 + + + bi bint{ii} 38432847329847329 + o object{ii} + b content true + a array{ii} + b content true + b content true + """); + } + List output = new .(); + List errors = new .(); + BofaParser.Parse(toParse, output, errors); + DeleteContainerAndItems!(output); + delete errors; + delete toParse; + } + } + + + + [Test(Name = "Profiling: normal 1 * 150000")] + public static void Profiling_Normal_Large() + { + String toParse = new .(10 * 150000); + for (int ii < 10000) + { + toParse.Append(scope $""" + l one{ii} line of text + b bool{ii} true + # saoidsaodsad + t text{ii} goes here + - Text addendum + n tone{ii} 12.5 + #husdhfiudshfds + bn biggie{ii} 65645645645.6 + i int{ii} 234345 + + + bi bint{ii} 38432847329847329 + o object{ii} + b content true + a array{ii} + b content true + b content true + + """); + } + List output = new .(); + List errors = new .(); + BofaParser.Parse(toParse, output, errors); + DeleteContainerAndItems!(output); + delete errors; + delete toParse; + } } \ No newline at end of file