diff --git a/DTLib/Experimental/Tester.cs b/DTLib/Experimental/Tester.cs index 523cd89..6107b6e 100644 --- a/DTLib/Experimental/Tester.cs +++ b/DTLib/Experimental/Tester.cs @@ -11,6 +11,7 @@ public static class Tester for (int i = 0; i < repeats; i++) operation(); clock.Stop(); - LogNoTime("c",$"operation {op_name} took {clock.ElapsedTicks / repeats} ticks"); + double time=(double)(clock.ElapsedTicks)/Stopwatch.Frequency/repeats; + LogNoTime("c",$"operation {op_name} took {time} seconds"); } } \ No newline at end of file diff --git a/DtsodC/src/Hashtable/Hashtable.c b/DtsodC/src/Hashtable/Hashtable.c index 68da148..775bb85 100644 --- a/DtsodC/src/Hashtable/Hashtable.c +++ b/DtsodC/src/Hashtable/Hashtable.c @@ -5,13 +5,16 @@ define_Autoarr2(KeyValuePair) // amount of rows static const uint16 HT_HEIGHTS[]={61,631,3889,19441,65521}; +#define ARR_BC 16 +#define ARR_BL 128 Hashtable* Hashtable_create(){ Hashtable* ht=malloc(sizeof(Hashtable)); - ht->hein=0; - ht->rows=malloc(HT_HEIGHTS[0]*sizeof(Autoarr2(KeyValuePair))); - for(uint16 i=0;irows[i]=Autoarr2_create(KeyValuePair,4,16); + //ht->hein=0;// + ht->hein=1; + ht->rows=malloc(HT_HEIGHTS[ht->hein]*sizeof(Autoarr2(KeyValuePair))); + for(uint16 i=0;ihein];i++) + ht->rows[i]=Autoarr2_create(KeyValuePair,ARR_BC,ARR_BL); return ht; } @@ -29,10 +32,10 @@ void Hashtable_free(Hashtable* ht){ uint32 Hashtable_height(Hashtable* ht){ return HT_HEIGHTS[ht->hein]; } -void Hashtable_resize(Hashtable* ht){ +void Hashtable_resize(Hashtable* ht){printf("RESIZE\n"); Autoarr2(KeyValuePair)* newrows=malloc(HT_HEIGHTS[++ht->hein]*sizeof(Autoarr2(KeyValuePair))); for(uint16 i=0;ihein];i++) - ht->rows[i]=Autoarr2_create(KeyValuePair,4,16); + ht->rows[i]=Autoarr2_create(KeyValuePair,ARR_BC,ARR_BL); for(uint16 i=0;ihein-1];i++){ Autoarr2(KeyValuePair)* ar=ht->rows+i; for(uint16 k=0;khein]; - if(rown>=HT_HEIGHTS[ht->hein]) - Hashtable_resize(ht); + //if(rown>=HT_HEIGHTS[ht->hein]) + // Hashtable_resize(ht); return ht->rows+rown; } diff --git a/DtsodC/src/main.c b/DtsodC/src/main.c index c5c1c6e..4c11d95 100644 --- a/DtsodC/src/main.c +++ b/DtsodC/src/main.c @@ -6,8 +6,8 @@ int main(){ setlocale(LC_ALL, "en-US.Unicode"); printf("\e[92mdtsod parser in c language!\e[97m\n"); - optime("test_all",1,{test_all();}); - //test_hashtable(); + //optime("test_all",1,{test_all();}); + test_hashtable(); printf("\e[0m\n"); return 0; } diff --git a/DtsodC/src/tests/test_hashtable.c b/DtsodC/src/tests/test_hashtable.c index 0bb6bfc..eaaabf9 100644 --- a/DtsodC/src/tests/test_hashtable.c +++ b/DtsodC/src/tests/test_hashtable.c @@ -14,26 +14,28 @@ void print_hashtable(Hashtable* ht){ void hashtable_fill(Hashtable* ht){ char* key=malloc(20); - for(uint32 i=0;i<100;i++){ + for(uint32 i=0;i<100000;i++){ sprintf(key,"key__%u",i); Hashtable_add(ht,key,Uni(UInt32,i)); } free(key); } -void hashtable_printval(Hashtable* ht){ +Unitype hashtable_printval(Hashtable* ht){ char* key=malloc(20); - for(uint32 i=0;i<100;i++){ + Unitype u; + for(uint32 i=0;i<100000;i++){ sprintf(key,"key__%u",i); - printuni(Hashtable_get(ht,key)); - printf(" "); + u=Hashtable_get(ht,key); + //printuni(u); printf(" "); } free(key); + return u; } void test_hashtable(void){ - optime("test_hashtable",1,({ + /* optime("test_hashtable",1,({ printf("\e[96m-----------[test_hashtable]------------\n"); Hashtable* ht=Hashtable_create(); print_hashtable(ht); @@ -42,5 +44,10 @@ void test_hashtable(void){ hashtable_printval(ht); Hashtable_free(ht); printf("\n\e[92mhashtable freed\n"); - })); + })); */ + printf("\e[96m-----------[test_hashtable]------------\n"); + Hashtable* ht=Hashtable_create(); + optime("fill",1,hashtable_fill(ht)); + optime("get",1,hashtable_printval(ht)); + Hashtable_free(ht); } diff --git a/DtsodC/src/tests/tests.h b/DtsodC/src/tests/tests.h index 6d1ae9f..3248c4a 100644 --- a/DtsodC/src/tests/tests.h +++ b/DtsodC/src/tests/tests.h @@ -16,5 +16,6 @@ void test_hashtable(void); for(uint64 ___OPREP=0;___OPREP dict){ + for(long i=0;i<100000;i++) + dict.Add($"key__{i}",i); + } + static long Gett(Dictionary dict){ + long r=0; + for(long i=0;i<100000;i++) + r=dict[$"key__{i}"]; + return r; + } + + static public void Test(){ + Console.WriteLine("----------------[dict.cs]----------------"); + Dictionary dict=new(); + LogOperationTime("fill",1,()=>Fill(dict)); + LogOperationTime("gett",1,()=>Gett(dict)); + } +} \ No newline at end of file diff --git a/TestProgram/DtsodV2X/TestDtsodV23.cs b/TestProgram/DtsodV2X/TestDtsodV23.cs index 798b67d..41e86cf 100644 --- a/TestProgram/DtsodV2X/TestDtsodV23.cs +++ b/TestProgram/DtsodV2X/TestDtsodV23.cs @@ -1,7 +1,4 @@ -using System.Threading; -using DTLib.Dtsod; -using DTLib.Experimental; -using static TestProgram.Program; +using static TestProgram.Program; namespace TestProgram.DtsodV2X; diff --git a/TestProgram/Program.cs b/TestProgram/Program.cs index 377eedf..0124e0e 100644 --- a/TestProgram/Program.cs +++ b/TestProgram/Program.cs @@ -3,11 +3,13 @@ global using System.Collections; global using System.Collections.Generic; global using System.Linq; global using System.Text; +global using System.Threading; global using System.Threading.Tasks; global using DTLib; global using DTLib.Extensions; +global using DTLib.Experimental; global using DTLib.Filesystem; -using DTLib.Dtsod; +global using DTLib.Dtsod; using DTLib.Loggers; using TestProgram.DtsodV2X; @@ -28,7 +30,8 @@ static class Program try { Info.Log("g","-------[DTLib tester]-------"); - TestDtsodV23.TestAll(); + //TestDtsodV23.TestAll(); + DictTest.Test(); } catch (Exception ex) { Info.Log("r", ex.ToString()); }