Thanks for your quick answer.
I did try to use only viewhash, for adding. But it did not change.
Here is a sample code you can run (attached)
200ms=time spent on 1 Select() !
I use a pentium 500Mhz

There must be something I dont understand...

Jean-Claude Wippler wrote:
Riccardo Cohen wrote:

I built a view of 50k records that I need to access. With normal view it is too slow (180 ms), so I try with hash view that I never used, and the result is even slower !(250 ms) !
(I've just read the new page http://www.equi4.com/mkmapping.html)


Here is what I've done :

  c4_View       view=db.GetAs("table[key:S,val:S]"),selection;
  c4_View       viewsec=db.GetAs("sec[_H:I,_R:I]");
  c4_View       viewhash=view.Hash(viewsec,1);
  c4_Row        row,searchrow;
  c4_StringProp val("val");
  c4_StringProp key("key");
  for (idx=0;idx<TOTAL;idx++)
  {
    sprintf(st1,"%d%d%d%d",idx,idx,idx,idx);
    sprintf(st2,"%d%d%d%d",idx,idx,idx,idx);
    key(row)=st1;
    val(row)=st2;
    view.Add(row);


No!  Do not touch view when there's a hash mapping on top.  Use viewhash:
      viewhash.Add(row)

  }
  db.Commit();
  key(searchrow)="5555";
  selection=viewhash.Select(searchrow);

what's wrong ?? is there any sample code ?


What are you measuring - total time of the above code? Yes, that will be slower, it is now also setting up hashes along the way. But the select should be instant.

One way to avoid the above confusion, it to rewrite your code a bit more and use:
view=view.Hash(viewsec,1);
at the top, replacing the "viewhash" declaration.


In other words, hide the original view once you've set up a hash on it.

-jcw

_______________________________________________
metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit



-- Riccardo Cohen

Articque
Les Roches
37230 Fondettes
France
email = [EMAIL PROTECTED]
web = http://www.articque.com
tel: +33 02 47 49 90 49
fax: +33 02 47 49 91 49


#include <mk4.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <sys/timeb.h> 
#include <sys/types.h>

main()
{
  struct _timeb tm1,tm2;
  unsigned long ms1,ms2;
  char          st1[200],st2[200];
  long          index,idx,curtime,totaltime;
  remove("tests");
  c4_Storage    db("tests",1);
  c4_View       view=db.GetAs("table[key:S,val:S]"),selection;
  c4_View       viewsec=db.GetAs("sec[_H:I,_R:I]");
  c4_Row        row,searchrow;
  c4_StringProp val("val");
  c4_StringProp key("key");
  view=view.Hash(viewsec,1);
  printf("write\n");
  for (idx=0;idx<50000;idx++)
  {
    sprintf(st1,"%dkey",idx);
    sprintf(st2,"%ddata",idx);
    key(row)=st1;
    val(row)=st2;
    view.Add(row);
  }
  db.Commit();
  printf("select\n");
  totaltime=0;
  for (idx=0;idx<100;idx++)
  {
    index=rand()%50000;
    sprintf(st1,"%dkey",idx);
    _ftime(&tm1);
    key(searchrow)=st1;
    selection=view.Select(searchrow);
    _ftime(&tm2);
    ms2=(unsigned long) (tm2.time*1000+tm2.millitm);
    ms1=(unsigned long) (tm1.time*1000+tm1.millitm);
    curtime=ms2-ms1;
    totaltime+=curtime;
    if (selection.GetSize()!=1)
    {
      printf("empty search\n");
      break;
    }
  }
  totaltime=totaltime/100;
  printf("avg=%d ms/search\n",totaltime);
  return(0);
}

/*
RESULT:
select
avg=194 ms/search
*/

Reply via email to