[Coldstuff] .join() vrs. join()
Brandon Gillespie
coldstuff@cold.org
Mon, 05 Aug 2002 13:04:42 -0600
Adam Cormany wrote:
> Is there a time when I should be using .join() instead
> of join() or is this just the users preference? On my
> system at least, join() seems a bit faster than
> .join():
>
> [06:07 PM:/home/s/soth] ;["a", "b"].join();
> => "a b"
> [ seconds: 0.000023; operations: 6 ]
>
> [06:08 PM:/home/s/soth] ;join(["a", "b"]);
> => "a b"
> [ seconds: 0.000007; operations: 6 ]
>
> The same goes for explode() and .explode():
> [06:08 PM:/home/s/soth] ;"a b".explode();
> => ["a", "b"]
> [ seconds: 0.000028; operations: 3 ]
>
> [06:10 PM:/home/s/soth] ;explode("a b");
> => ["a", "b"]
> [ seconds: 0.000012; operations: 3 ]
>
They are the same code underneath, but are initiated differently.
join() is an operator, similar to '+' and '*' etc. So it will be
initiated MUCH quicker than a native method call (.join()) which has a
method operator '.' followed by looking up the method, building the
frame, then executing the native code. The differences you are seeing
are the differences between these two actions. both are nominal,
however. The method-call syntax is highly useful when chaining
something (foo.explode().join()).
-Brandon