<br><br><div class="gmail_quote">2010/9/29 Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div></div><div>On Thu, 30 Sep 2010, Igor Stasenko wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 15 May 2010 02:43, Igor Stasenko &lt;<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 15 May 2010 02:35, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The cardinal rule of running benchmarks is to compare apples to apples.<br>
 You&#39;ve compared apples to oranges, i.e. an optimized reimplementation of<br>
WideString&gt;&gt;hash that eliminates the mapping of codes to characters, against<br>
the vanilla Squeak implementation.  You need to at least compare the NB<br>
implementation against<br>
WideString methods for comparison<br>
fastHash<br>
| stringSize hash low |<br>
stringSize := self size.<br>
hash := ByteString identityHash bitAnd: 16rFFFFFFF.<br>
1 to: stringSize do: [:pos |<br>
hash := hash + (self wordAt: pos).<br>
&quot;Begin hashMultiply&quot;<br>
low := hash bitAnd: 16383.<br>
hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low)<br>
bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF.<br>
].<br>
^ hash<br>
| s n |<br>
s := (WideString with: (Character value: 16r55E4)) , &#39;abcdefghijklmno&#39;.<br>
n := 100000.<br>
{ [1 to: n do: [:i| s fastHash. s fastHash. s fastHash. s fastHash. s<br>
fastHash. s fastHash. s fastHash. s fastHash. s fastHash. s fastHash]]<br>
timeToRun.<br>
 [1 to: n do: [:i| s hash. s hash. s hash. s hash. s hash. s hash. s hash. s<br>
hash. s hash. s hash]] timeToRun. }<br>
     #(829 1254)<br>
ASo your measurements tell us nothing about a general comparison of NB<br>
against the Squeak VM or Cog.  They only demonstrate (unsurprisingly) that a<br>
loop summing integers in an array goes PDQ.  On the other hand my numbers<br>
showed Cog 10x faster than the Squeak interpreter when executing exactly the<br>
same bytecode.<br>
</blockquote>
<br>
Yes, of course you&#39;re right.<br>
But i didn&#39;t compared it with Cog, because i can&#39;t.<br>
And NB is not for translating bytecodes into native code,<br>
it is for authoring a primitives using native code.<br>
So, my comparison is how faster it could be , if implemented primitively.<br>
<br>
I can only imagine, how faster the whole thing would be if we<br>
cross-hatch NB and Cog,<br>
where Cog will serve as a smalltalk optimizer , and NB will serve for<br>
manual optimizations<br>
for heavy numerical crunching :)<br>
<br>
</blockquote>
<br>
Its now time to verify things, since now i can run native code under Cog:<br>
<br>
|ss s t1 t2 t3 |<br>
s := (WideString with: (Character value: 16r55E4)) , &#39;abcdefghijklmno&#39;.<br>
ss := (String with: $z) , &#39;abcdefghijklmno&#39;.<br>
<br>
10 timesRepeat: [ s := s , s. ss := ss , ss ].<br>
self assert: (s hash = s nbHash).<br>
t1 := [1000 timesRepeat: [s hash]] timeToRun.<br>
t2 := [1000 timesRepeat: [s nbHash]] timeToRun.<br>
t3 := [1000 timesRepeat: [ss hash]] timeToRun.<br>
{ t1. t2. t3 }<br>
<br>
Squeak VM:<br>
<br>
#(7929 89 125)<br>
</blockquote>
<br></div></div>
You should update your image, because WideString&#39;s hash is now ~2x faster than before with SqueakVM. I get #(3822 119) for t1 and t3.<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cog VM:<br>
<br>
#(1256 88 99)<br>
<br>
<br>
However, in tight loops, where loop&#39;s payload comparable to function&#39;s<br>
payload itself, Cog is a winner:<br>
<br>
|s|<br>
s := WideString with: (Character value: 16r55E4).<br>
[10000000 timesRepeat: [s hash]] timeToRun.<br>
1307<br>
<br>
|s|<br>
s := WideString with: (Character value: 16r55E4).<br>
[ s hash ] bench<br>
&#39;2,840,000 per second.&#39;<br>
<br>
|s|<br>
s := WideString with: (Character value: 16r55E4).<br>
[10000000 timesRepeat: [s nbHash]] timeToRun.<br>
<br>
1438<br>
<br>
|s|<br>
s := WideString with: (Character value: 16r55E4).<br>
[ s nbHash ] bench<br>
&#39;2,710,000 per second.&#39;<br>
<br>
obviously, because it can&#39;t inline a native code generated by NB :)<br>
</blockquote>
<br></div>
Can Cog inline message sends? I thought it can&#39;t ATM.<br></blockquote><div><br></div><div>Right.  But the thought is that because Cog does inline machine-code for certain primitives (actually it generates machine-code versions of core primitives) that with a little work NB would be able to generate the machine code for primitives that Cog&#39;s code generator doesn&#39;t handle.  </div>
<div><br></div><div>Igor will correct me if I&#39;m wrong but I think the idea is thus.  NB-generated code needs to be stored somewhere in a CompiledMethod where Cog can find it, along with some link-edit metadata to allow Cog to fix-up data references in the code etc.  If Cog finds a method containing NB code it copies this code into the start of the method (where primitive code is compiled) and does some simple link-editing on the code.  Now the Cog method starts with NB code which operates ;like a primitive, jumping to the start of the Cog method proper if it fails.</div>
<div><br></div><div>If we&#39;re talking about NB FFI calls then there&#39;s additional compilations.  A stack switch is required from Cog&#39;s stack pages to the real C stack, and back on return, etc.  But I&#39;m encouraged that Igor has already got NB going on Cog.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Btw, can you send a message from NB code?<br></blockquote><div><br></div><div>As I understand it, no.</div><div><br></div><div>best</div><div>Eliot</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font color="#888888">
<br>
<br>
Levente</font><div><div></div><div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-- <br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</blockquote>
</div></div><br><br>
<br></blockquote></div><br>