Objects in rebol
[1/2] from: kevin1::chorg::darpa::org at: 19-Jun-2001 17:59
Does using OOP in rebol (REBOL)? slow down the language at all? Usually OOP
does do that , but the slowdown varies from lang to lang. How about rebol?
[2/2] from: joel:neely:fedex at: 19-Jun-2001 17:01
Hi, Kevin,
kevin1 wrote:
> Does using OOP in rebol (REBOL)? slow down the language at
> all? Usually OOP does do that , but the slowdown varies
> from lang to lang. How about rebol?
>
It depends on what you're doing, but I ran one quick test as
described below. The usual trade-off is between using passive
data structures fed to as arguments to functions versus using
objects with method calls.
I build a block of a few thousand copies of a reference to
[17 42 666]
then looped through them a few thousand times feeding each
block to
sum-blk: func [b [block!]] [b/1 + b/2 + b/3]
then again the same number of times feeding the components of
each block to
sum-args: func [a [integer!] b [integer!] c [integer!]] [
a + b + c
]
Then, using a specimen object:
obj: make object! [
a: 17
b: 42
c: 666
sum-of: does [a + b + c]
]
I built the same number of objects using OBJ as a prototype,
then looped through them, calling the SUM-OF method on each.
With equivalent counts,
sum-blk 196 seconds
sum-args 229 seconds
sum-of 227 seconds
So, for this little test, the overhead of using an object is
roughly the same as the overhead of passing separate arguments
pulled out of a data structure.
However, REBOL objects have another cost factor; every time we
create a new object using (for example):
foo: make obj []
the new object gets a copy of *all* components, whether they
are "data-like" or "method-like" (REBOL doesn't distinguish
between data and code).
Hope this helps!
-jn-
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com