On Wed, 05 Nov 2008, Szak�ts Viktor wrote:

Hi Viktor,

>                           r9830  r9838
> __i18n_loadfrommemory():   3.72   3.72
> __i18n_gettext():          3.39   3.33
> hb_deserialize():         10.26   4.41
> hash lookup:               2.58   4.16
> For some reason simple hash lookup became
> a bit slower, and now 30% slower than
> __i18n_gettext() (previously it was 30%
> faster). Still pretty good though. I wonder
> what may cause this.

Probably there are some different conditions in tests.
Binary search is noticeable faster then the previous one.
Below I'm attaching test code.
You asked about eliminating two scans in code like:
   if cText $ h
      cText := h[ cText ]
   endif
   return cText
And I see that Mindaugas gave perfect answer. If you rewrite
this code in C then it will use only one pass.
Anyhow here we can think about adding yet another feature to
hash arrays. We can introduce new hash flag that will indicate
that on access when variable with given key does not exists in
hash array then this key is return. In such case the above code
will look like:
   return h[ cText ]
We can also make the same functionality in different way and instead
of intorducing new flag we can add special syntax for such situation,
f.e.:
   return h[ @cText ]

this is only for perofrmance reasons. Using C we can easy write function
like:

   HB_FUNC( HB_HKEY )
   {
      PHB_ITEM pHash = hb_param( 1, HB_IT_HASH );
      PHB_ITEM pKey = hb_param( 2, HB_IT_HASHKEY );

      if( pHash && pKey )
      {
         ULONG ulPos;
         hb_hashScan( pHash, pKey, &ulPos );
         if( ulPos )
            pKey = hb_hashGetValueAt( pHash, ulPos );
         hb_itemReturn( pKey );
      }
      else
         hb_errRT_BASE( EG_BOUND, 1133, NULL, hb_langDGetErrorDesc( 
EG_ARRASSIGN ), 2, pHash, pKey );
   }

and in such case the above .prg code will look like:

   return hb_hKey( h, cText )

but I haven't check how big overhead will be caused by function
call in this case. You can try to compare:

   func f1(cText,h)
   if cText $ h
      cText := h[ cText ]
   endif
   return cText

with:

   func f2(cText,h)
   return hb_hKey( h, cText )

best regards,
Przemek


best regards,
Przemek


#define N_LOOP 10000
#define N_SIZE 1000

proc main()
   local h1, h2, aKeys, i, n, t, tn, x
   h1 := {=>}
   h2 := {=>}
   hb_hSetBinary(h2,.f.)
   aKeys := array(N_SIZE)
   for i:=1 to N_SIZE
      aKeys[i] := "[" + str( i, i%20+10 ) +"]"
      h1[ aKeys[i] ] := aKeys[i]
      h2[ aKeys[i] ] := aKeys[i]
   next

   t := secondsCPU()
   for n:=1 to N_LOOP
      for i:=1 to N_SIZE
         x := aKeys[i]
      next
   next
   tn := secondsCPU() - t
   ? "Other code overhead", tn, "sec."

   t := secondsCPU()
   for n:=1 to N_LOOP
      for i:=1 to N_SIZE
         x := h1[ aKeys[i] ]
      next
   next
   ? "Binary hash:", secondsCPU() - t - tn, "sec."

   t := secondsCPU()
   for n:=1 to N_LOOP
      for i:=1 to N_SIZE
         x := h2[ aKeys[i] ]
      next
   next
   ? "Binary hash:", secondsCPU() - t - tn, "sec."

return
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to