Hi Przemek,

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.

Dunno, my test is far from extensive, and several
optimally and less optimally placed strings should
have to be searched (or all), but that was the consistent
result for my example. (I tried to use a less-optimal
one, at the beginning of the sorted list, to better
highlight the differences). Anyhow, let's not be
blocked by this result, I believe you it's optimal.

Maybe dropping such features as discussed in other
thread (tweaking internal sort and other xhb
historic features), could further enhance speed.

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 ]

Both excellent. I cannot see the consequences if implementation
and as a brand new hash user it's hard to tell which feels more
natural. Maybe the second one is more elegant. And/or we could
have an alternative hb_HGet???() function with same functionality.

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

  HB_FUNC( HB_HKEY )
  {
  }

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

  return hb_hKey( h, cText )

See above :) I think we could have this also. But
for below reasons, the simple assignment above
is superior for this case.

func f2( cText, h )
   return h[ @cText ]

I'll do some tests a bit later.

Brgds,
Viktor

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 )

#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.)
...

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

Reply via email to