<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NeXuS VUS (Very Unuseful Stuff) &#187; Programming</title>
	<atom:link href="http://nexus.thenexus.it/wordpress/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://nexus.thenexus.it/wordpress</link>
	<description>About me, my thoughts, my life and much other unuseful stuff... :)</description>
	<lastBuildDate>Mon, 09 Aug 2010 05:15:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Stackless Python vs. Go</title>
		<link>http://nexus.thenexus.it/wordpress/2009/11/19/stackless-python-vs-go/</link>
		<comments>http://nexus.thenexus.it/wordpress/2009/11/19/stackless-python-vs-go/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 10:17:18 +0000</pubDate>
		<dc:creator>NeXuS</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://nexus.thenexus.it/wordpress/2009/11/19/stackless-python-vs-go/</guid>
		<description><![CDATA[Note: I did a little more research and it turns out that the gc runtime creates one OS thread only, and then adds threads as a way to avoid I/O locks. On the other hand the gccgo runtime maps goroutines &#8230; <a href="http://nexus.thenexus.it/wordpress/2009/11/19/stackless-python-vs-go/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Note</strong>: I did a little more research and it turns out that <strong>the gc runtime creates one OS thread only, and then adds threads as a way to avoid I/O locks.</strong> On the other hand <strong>the gccgo runtime maps goroutines and p_threads on a 1 to 1 basis</strong> (as of now).</p>
<p>I have been lazily following the Go language project for a while now, when it<br />
was suddenly discussed in this post of &#8220;Appunti Digitali&#8221; (in italian), that<br />
pointed at <a href="http://dalkescientific.com/writings/diary/archive/2009/11/15/<br />
100000_tasklets.html" title="100,000 tasklets: Stackless and Go">this post</a><br />
on Dalke Scientific. </p>
<p>It really got me that S.Python manages to beat Go so<br />
badly, so I decided to run my own tests on my trusty old IBM X-41 (Pentium-M 1.5<br />
GHz).</p>
<p><span id="more-547"></span></p>
<p>I compiled the Go toolchain and S.Python, then ran the<br />
test exactly as I found them on the Dalke page. The results are following<br />
hereby:</p>
<p><code>$ time ./8.out <br />100000</p>
<p>real 0m5.197s <br />user 0m1.508s <br />sys 0m1.352s</code></p>
<p><code>$ time<br />
/usr/local/bin/python2.6 test.py <br />100000 </p>
<p>real 0m3.315s <br />user 0m1.556s <br />sys 0m0.148s</code></p>
<p>What really struck me is that<br />
the time spent in userland is roughly the same for both programs. What really<br />
kills the Go execution time is that it spends almost as much time in kernel<br />
mode. I wondered why&#8230;</p>
<p>Then I remembered that, in the Google Tech Talk,<br />
Pike said something about the Go runtime managing threads for the user, and I<br />
automatically thought that it would associate user threads with OS threads in<br />
some way (as is the norm). In fact that is what gccgo does (uses NTPL).</p>
<p>On<br />
the other hand, reading Stackless Python documentation, I found this page<br />
regarding <a href="http://zope.stackless.com/wiki/Tasklets" title="Stackless<br />
Python: Tasklets">Tasklets</a>. The page clearly states: &#8220;Tasklets are<br />
characterized by being very lightweight and portable, and make great<br />
alternatives to system threads or processes.&#8221;</p>
<p>So I am prone to believe<br />
that S.Python Tasklets are managed by the Python VM itself, requiring no<br />
user-to-kernel mode transitions and no other kernel interaction&#8230; because they<br />
are not real threads (as opposed to Go goroutines).</p>
<p>This, with the fact<br />
that <em>Go is mainly intended to cut compile time</em> (not so much running<br />
time), makes me believe the comparison to be pretty unfair, and I think Go<br />
provides quite a performance!</p>
<p>Regarding certain unsafe situations, they<br />
are definitely a problem. Still, I believe that they will be taken care of<br />
quickly: Go is a brand new language and rough edges are to be expected here and<br />
there, but it has quite some room for growth.</p>
<p><strong>Update:</strong></p>
<p>I modified the test program so that each goroutine/Tasklet calls a second<br />
function that loops 1000 times and cumulates the result of &#8220;sum = sum+1&#8243;.</p>
<p>The results are as expected: the compiled code is one order of magnitude faster<br />
than Stackless Python interpreted code! I also replaced range with xrange, as <a href="http://www.appuntidigitali.it/4998/ce-posto-per-google-go-prime-<br />
impressioni-sul-nuovo-linguaggio-di-bigg/#comment-27071">suggested</a> by Cesare<br />
Di Mauro, but that did not change things much&#8230; nor did it when I tried psyco<br />
(a JIT compiler for Python).</p>
<p>
<code><br />
$time ./test2 &#038;&#038; time /usr/local/bin/python test2.py<br />
100000</p>
<p>real    0m4.037s<br />
user    0m1.040s<br />
sys     0m0.840s<br />
100000</p>
<p>real    0m19.567s<br />
user    0m15.697s<br />
sys     0m0.160s<br />
</code>
</p>
<p>The source code for Python is:<br />
<code lang="python'><br />
import stackless<br />
from optparse import OptionParser</p>
<p>parser = OptionParser()<br />
parser.add_option("-n", type="int", dest="num_tasklets", help="how many",<br />
default=100000)</p>
<p>def f(left, right):<br />
    loop()<br />
    left.send(right.receive()+1)</p>
<p>def loop():<br />
    sum = 0<br />
    for i in xrange (1,1000):<br />
        sum=sum+1</p>
<p>def main():<br />
    options, args = parser.parse_args()<br />
    leftmost = stackless.channel()<br />
    left, right = None, leftmost<br />
    for i in xrange(options.num_tasklets):<br />
        left, right = right, stackless.channel()<br />
        stackless.tasklet(f)(left, right)<br />
    right.send(0)<br />
    x = leftmost.receive()<br />
    print x</p>
<p>stackless.tasklet(main)()<br />
stackless.run()<br />
</code></p>
<p>And the test code for Go is:<br />
<code lang="c'><br />
package main</p>
<p>import (<br />
        "flag";<br />
        "fmt";<br />
)</p>
<p>var ngoroutine = flag.Int("n", 100000, "how many")</p>
<p>func f(left, right chan int) {<br />
        loop();<br />
        left < - 1+<-right;<br />
}</p>
<p>func loop() {<br />
        var sum int;<br />
        sum = 0;<br />
        for i := 0; i < 1000; i++ {<br />
                sum = sum + 1<br />
        }<br />
}</p>
<p>func main() {<br />
        flag.Parse();<br />
        leftmost := make(chan int);<br />
        var left, right chan int = nil, leftmost;<br />
        for i := 0; i < *ngoroutine; i++ {<br />
                left, right = right, make(chan int);<br />
                go f(left, right);<br />
        }<br />
        right <- 0;             // bang!<br />
        x := <-leftmost;        // wait for completion<br />
        fmt.Println(x);         // 100000<br />
}<br />
</code><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://nexus.thenexus.it/wordpress/2009/11/19/stackless-python-vs-go/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Stopping Qt compilation</title>
		<link>http://nexus.thenexus.it/wordpress/2009/08/31/506/</link>
		<comments>http://nexus.thenexus.it/wordpress/2009/08/31/506/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:43:00 +0000</pubDate>
		<dc:creator>NeXuS</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[What?]]></category>

		<guid isPermaLink="false">http://nexus.thenexus.it/?p=506</guid>
		<description><![CDATA[Today I tried stopping Qt complation on my Windows maching (using MS compiler). Here are the last few lines of output. moc_formextractor.cpp moc_mainwindow.cpp Generating Code... cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT &#8230; <a href="http://nexus.thenexus.it/wordpress/2009/08/31/506/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I tried stopping Qt complation on my Windows maching (using MS compiler).</p>
<p>Here are the last few lines of output.<span id="more-506"></span></p>
<p><code><br />
moc_formextractor.cpp<br />
moc_mainwindow.cpp<br />
Generating Code...<br />
        cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189<br />
-DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_<br />
LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"..\..\..\include\QtCore" -I"..\..\..\in<br />
clude\QtGui" -I"..\..\..\include\QtWebKit" -I"..\..\..\include" -I"..\..\..\incl<br />
ude\ActiveQt" -I"tmp\moc\release_static" -I"." -I"." -I"..\..\..\mkspecs\win32-m<br />
svc2008" -Fotmp\obj\release_static\ @C:\DOCUME~1\MASSIM~1.CIL\LOCALS~1\Temp\nmA2<br />
E.tmp<br />
qrc_formextractor.cpp<br />
        link /LIBPATH:"c:\Qt\2009.03\qt\lib" /LIBPATH:"c:\Qt\2009.03\qt\lib" /NO<br />
LOGO /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:"tmp\obj\release_static\formExtract<br />
or.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' n<br />
ame='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b6<br />
4144ccf1df' language='*' processorArchitecture='*'" /OUT:release\formExtractor.e<br />
xe @C:\DOCUME~1\MASSIM~1.CIL\LOCALS~1\Temp\nmA2F.tmp<br />
NNNMMMNAAAMKKKAEEEK   E:::    :fff aaaftttaaaatllla   leee rrrerrrrooorrrro   rU<br />
UU 111U000155508885:::8   : NMAKE : fatal error U1058: ttttteeeeerrrrrmmmmmiiiii<br />
nnnnnaaaaattttteeeeeddddd     bbbbbyyyyy     uuuuussssseeeeerrrrr</p>
<p>SSSSStttttoooooppppp.....<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://nexus.thenexus.it/wordpress/2009/08/31/506/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About ComboBox and Data binding (.NET, C#)</title>
		<link>http://nexus.thenexus.it/wordpress/2006/04/03/about-combobox-and-data-binding-net-c/</link>
		<comments>http://nexus.thenexus.it/wordpress/2006/04/03/about-combobox-and-data-binding-net-c/#comments</comments>
		<pubDate>Mon, 03 Apr 2006 12:36:52 +0000</pubDate>
		<dc:creator>NeXuS</dc:creator>
				<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://nexus.thenexus.it/wordpress/2006/04/03/about-combobox-and-data-binding-net-c/</guid>
		<description><![CDATA[So, it seems like I am not able to post about anything else than IT! Anyway, I had this strange problem with the ComboBox control of the .NET 2.0 framework (but I guess the problem would have been manifest with &#8230; <a href="http://nexus.thenexus.it/wordpress/2006/04/03/about-combobox-and-data-binding-net-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, it seems like I am not able to post about anything else than IT! <img src='http://nexus.thenexus.it/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyway, I had this strange problem with the ComboBox control of the .NET 2.0 framework (but I guess the problem would have been manifest with version 1.0/1.1 too):<br />
I had some ComboBoxes that I had been binding to some DataTables generated as the result of some Stored Procedure calls on a DB server. Everything seemed to be working until I tried to set the ComboBox.SelectedValue property manually: disaster happened and nothing worked as it should have.</p>
<p>The reason for this strange behaviour was that I did not add the ComboBoxes to the form Control list BEFORE binding the source!<br />
The worst thing of it all is that I have not been able to find any clue about the order in which these two operations whould be done on the MSDN, nor on various developer forums!</p>
<p>So rememeber:</p>
<ul>
<li>First add the controls to your form</li>
<li>And only then you can correctly set the DataSource</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://nexus.thenexus.it/wordpress/2006/04/03/about-combobox-and-data-binding-net-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
