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

Hi Viktor,

[...]
> I'll do some tests a bit later.

Below is small test code I've just created.
Here I my results:

   __I18N_LOADFROMMEMORY:         5.93 sec.
   hb_deserialize:                6.63 sec.
   other code overhead:           2.28 sec.
   __I18N_GETTEXT:               16.11 sec.
   HB_HKEY:                      12.08 sec.
   Native hash .prg access:      20.03 sec.

Looks that function call overhead is not too big in this test.

best regards,
Przemek


#define N_LOOP 1000
#define N_SIZE 10000
proc main()
   local a, h, aMem, hMem, i, n, t, tn, cKey, aKeys

   ? "Building arrays..."
   h := {=>}
   hb_hAllocate( h, N_SIZE )
   a := array( N_SIZE )
   aKeys := array( N_SIZE )
   for i:=1 to N_SIZE
      cKey := repl("text.", 9) + "[" + str(i,10) + " ]" + ;
              repl( "*", i % 20 )
      aKeys[ i ] := cKey
      a[ i ] := { cKey, upper( cKey ) }
      h[ cKey ] := upper( cKey )
   next
   aSort( a,,, { |x,y| x[1] < y[1] } )
   ? "Saving arrays to files"
   __I18N_SAVE( "data.arr", a )
   hb_memowrit( "data.hsh", hb_serialize( h ) )

   aMem := memoread( "data.arr" )
   hMem := memoread( "data.hsh" )

   t := secondsCPU()
   for i := 1 TO N_LOOP
      a := __I18N_LOADFROMMEMORY( aMem )
   next
   ? "__I18N_LOADFROMMEMORY:", secondsCPU() - t, "sec."

   t := secondsCPU()
   for i := 1 TO N_LOOP
      h := hb_deserialize( hMem )
   next
   ? "hb_deserialize:", secondsCPU() - t, "sec."

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


   t := secondsCPU()
   for i := 1 TO N_LOOP
      for n := 1 to N_SIZE
         cKey := aKeys[ n ]
         cKey := __I18N_GETTEXT( cKey, a )
      next
   next
   ? "__I18N_GETTEXT:", secondsCPU() - t - tn, "sec."

   t := secondsCPU()
   for i := 1 TO N_LOOP
      for n := 1 to N_SIZE
         cKey := aKeys[ n ]
         cKey := HB_HKEY( h, cKey )
      next
   next
   ? "HB_HKEY:", secondsCPU() - t - tn, "sec."

   t := secondsCPU()
   for i := 1 TO N_LOOP
      for n := 1 to N_SIZE
         cKey := aKeys[ n ]
         if cKey $ h
            cKey := h[ cKey ]
         endif
      next
   next
   ? "Native hash .prg access:", secondsCPU() - t - tn, "sec."

return

#pragma begindump
#include "hbapi.h"
#include "hbapierr.h"

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_ARG, 1123, NULL, HB_ERR_FUNCNAME,
                     HB_ERR_ARGS_BASEPARAMS );
}
#pragma enddump
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to