DictTest
This commit is contained in:
parent
a8dd8de77b
commit
f9a844447d
@ -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");
|
||||
}
|
||||
}
|
||||
@ -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;i<HT_HEIGHTS[0];i++)
|
||||
ht->rows[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;i<HT_HEIGHTS[ht->hein];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;i<HT_HEIGHTS[ht->hein];i++)
|
||||
ht->rows[i]=Autoarr2_create(KeyValuePair,4,16);
|
||||
ht->rows[i]=Autoarr2_create(KeyValuePair,ARR_BC,ARR_BL);
|
||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){
|
||||
Autoarr2(KeyValuePair)* ar=ht->rows+i;
|
||||
for(uint16 k=0;k<Autoarr2_length(ar);k++){
|
||||
@ -47,8 +50,8 @@ void Hashtable_resize(Hashtable* ht){
|
||||
|
||||
Autoarr2(KeyValuePair)* getrow(Hashtable* ht, char* key){
|
||||
uint16 rown=ihash(key)%HT_HEIGHTS[ht->hein];
|
||||
if(rown>=HT_HEIGHTS[ht->hein])
|
||||
Hashtable_resize(ht);
|
||||
//if(rown>=HT_HEIGHTS[ht->hein])
|
||||
// Hashtable_resize(ht);
|
||||
return ht->rows+rown;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -16,5 +16,6 @@ void test_hashtable(void);
|
||||
for(uint64 ___OPREP=0;___OPREP<repeats;___OPREP++)\
|
||||
(codeblock);\
|
||||
clock_t stop=clock();\
|
||||
printf("\e[93moperation %s took \e[94m%ld \e[93mticks\n",opname,(stop-start));\
|
||||
double t=(double)(stop-start)/CLOCKS_PER_SEC/repeats;\
|
||||
printf("\e[93moperation %s took \e[94m%lf \e[93mseconds\n",opname,t);\
|
||||
})
|
||||
|
||||
24
TestProgram/DtsodC/DictTest.cs
Normal file
24
TestProgram/DtsodC/DictTest.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using static DTLib.Experimental.Tester;
|
||||
|
||||
namespace TestProgram;
|
||||
|
||||
static class DictTest
|
||||
{
|
||||
static void Fill(Dictionary<string,long> dict){
|
||||
for(long i=0;i<100000;i++)
|
||||
dict.Add($"key__{i}",i);
|
||||
}
|
||||
static long Gett(Dictionary<string,long> 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<string,long> dict=new();
|
||||
LogOperationTime("fill",1,()=>Fill(dict));
|
||||
LogOperationTime("gett",1,()=>Gett(dict));
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,4 @@
|
||||
using System.Threading;
|
||||
using DTLib.Dtsod;
|
||||
using DTLib.Experimental;
|
||||
using static TestProgram.Program;
|
||||
using static TestProgram.Program;
|
||||
|
||||
namespace TestProgram.DtsodV2X;
|
||||
|
||||
|
||||
@ -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()); }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user