new allocate_string functions

new topic     » topic index » view thread      » older message » newer message

Hi, Dear EU users:

There is the allocate_string() function
in the standard RDS machine.e library.

Try please some variations on this theme:

include machine.e
object ok

-- without type_check

global function pointer_1(sequence s)
    atom a
     s &= 0
     a = machine_func(16,length(s))
    if a then
	poke(a, s)
    end if
    return a
end function

global function pointer_2(sequence s)
    atom a 
     a = machine_func(16,length(s) + 1)
    if a then
	poke(a, s & 0)
    end if
    return a
end function

integer l
atom a 
global function pointer_3(sequence s)
     l = length(s) + 1
     a = machine_func(16, l)
    if a then
	poke(a, s & 0) 
    end if
    return a
end function

global function pointer_4(sequence s)
     l = length(s)
     a = machine_func(16, l+1)
    if a then
	poke(a, s)
	poke(a+l, 0)  -- Thanks to Aku
    end if
    return a
end function

global function pointer_5(sequence s)
atom a
integer l
     l = length(s)
     a = machine_func(16, l+1)
    if a then
	poke(a, s)
	poke(a+l, 0)  -- Thanks to Aku
    end if
    return a
end function

sequence test
  test = "proba pera iz gusinogo kryla" --1
       & "proba pera iz gusinogo kryla" --2
       & "proba pera iz gusinogo kryla" --3

atom T, A, N
N=10000000
---1
T= time()
for i=1 to N do
  A = allocate_string(test)
    machine_proc(17, A)
end for
A = time()
? A - T
---2
T= time()
for i=1 to N do
  A = pointer_1(test)
    machine_proc(17, A)
end for
A = time()
? A - T
---3
T= time()
for i=1 to N do
  A = pointer_2(test)
    machine_proc(17, A)
end for
A = time()
? A - T
---4
T= time()
for i=1 to N do
  A = pointer_3(test)
    machine_proc(17, A)
end for
A = time()
? A - T
---5
T= time()
for i=1 to N do
  A = pointer_4(test)
    machine_proc(17, A)
end for
A = time()
? A - T
---6
T= time()
for i=1 to N do
  A = pointer_5(test)
    machine_proc(17, A)
end for
A = time()
? A - T

ok = getc(0)


I have the following results on P4 1.8GHz:

                    1   &   2    &   3        1&2&3 without type_check
allocate_string() 12.16   14.428   15.961   15.514   
pointer_1()       10.206  12.825   15.517   15.228   -- simplest one
pointer_2()       10.141  12.977   15.471   15.013
pointer_3()       10.91   13.353   15.818   15.5
pointer_4()        8.123  10.154   12.145   11.678   -- fastest one
pointer_5()        8.327  10.347   12.097   11.781

These new functions have the automated type check
for the machine_func() call - length(s), so they 
do not need any wrapped calls (via allocate()),
it seems to me.

Use on your own risk!   blink

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu