Tuesday, November 24, 2009

Templates v subclasses v.2

A slightly more complicated test similar to the previous post. In this case the templated version doesn't have such a huge advantage.

Subclassed version:

#include <iostream>

using namespace std;

class mybaseclass {
public:

virtual int get_i() = 0;
};

class myclass : public mybaseclass {

public:

myclass(int in) {
i=in;
}

int get_i() {
i++;
return i;
}

int i;
};

class otherclass : public mybaseclass {

public:

otherclass(int in) {
i = in;
}

int get_i() {
return i*i;
}

int i;
};

int main(void) {
myclass *c = new myclass(2);

double sum=0;
for(size_t n=0;n<2000000000;n++) {

mybaseclass *cc = c;

sum += (static_cast<double>(cc->get_i())/2.2);

}
cout << sum << endl;
delete c;
}


Templated version:
#include <iostream>

using namespace std;

template<class t>
class myclass {

public:

myclass(int in) {
i=in;
}

inline int get_i() {
i++;
return i;
}

int i;
};

template<class t>
class otherclass {

public:

otherclass(int in) {
i = in;
}

inline int get_i() {
return i*i;
}

int i;
};

int main(void) {
myclass<int> *c = new myclass<int>(2);

double sum=0;
for(size_t n=0;n<2000000000;n++) {

sum += (static_cast<double>(c->get_i())/2.2);

}
cout << sum << endl;
delete c;
}



$ g++ small_classed.cpp -O3;time ./a.out
9.09091e+17

real 0m21.151s
user 0m20.909s
sys 0m0.072s


$ g++ small_templateclassed.cpp -O3;time ./a.out
9.09091e+17

real 0m20.736s
user 0m20.527s
sys 0m0.064s

Are templates faster than subclasses?

Are template classes faster than using a derived class? Intuition would tell me that the template class should be faster. However to test if this is the case I wrote the following small programs:

Subclassed version:

#include <iostream>

using namespace std;

class mybaseclass {
public:

virtual int get_i() = 0;
};

class myclass : public mybaseclass {

public:

myclass(int in) {
i=in;
}

int get_i() {
return i;
}

int i;
};

class otherclass : public mybaseclass {

public:

otherclass(int in) {
i = in;
}

int get_i() {
return i*i;
}

int i;
};

int main(void) {
myclass *c = new myclass(2);
long int sum=0;
for(size_t n=0;n<2000000000;n++) {
mybaseclass *cc = c;

sum += cc->get_i();

}
cout << sum << endl;
delete c;
}



Templated version:
#include <iostream>

using namespace std;

template<class t>
class myclass {

public:

myclass(int in) {
i=in;
}

int get_i() {
return i;
}

int i;
};

template<class t>
class otherclass {

public:

otherclass(int in) {
i = in;
}

int get_i() {
return i*i;
}

int i;
};

int main(void) {
myclass<int> *c = new myclass<int>(2);

long int sum=0;
for(size_t n=0;n<2000000000;n++) {

sum += c->get_i();

}
cout << sum << endl;
delete c;
}




$g++ small_templateclassed.cpp -O3;time ./a.out
4000000000

real 0m0.008s
user 0m0.000s
sys 0m0.001s


$ g++ small_classed.cpp -O3;time ./a.out
4000000000

real 0m5.908s
user 0m5.853s
sys 0m0.018s

My first effort was IO bound, but in this case it appears that templatized code is substantially faster.

Nabble thread is here.

Friday, November 20, 2009

Renicing synology nfsd so it has priority over other services

We needed nfs to have priority over other services on a synology DS509+. To do this we reniced the nfsd process. Synologies are basically just linux boxes. So enable ssh on the synology and ssh to it (ssh synology -lroot) use your normal admin password for the password. Then edit /usr/syno/etc/rc.d/S83nfsd.sh. Where it currently reads:

/sbin/portmap
/usr/sbin/nfsd
/usr/sbin/mountd -p 892
;;
stop)

change it to read:

/usr/sbin/nfsd
/usr/sbin/mountd -p 892
renice -10 `pidof nfsd`

;;
stop)

Monday, November 16, 2009

Commands used to install golang


Commands I used to install Go language (golang) on Ubuntu amd64:

sudo apt-get install mercurial bison gcc libc6-dev ed make
cd ~
export GOROOT=$HOME/go
export GOARCH=amd64
export GOOS=linux
mkdir $HOME/gobin
export GOBIN=$HOME/gobin
export PATH=$PATH:$GOBIN
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
cd $GOROOT/src
./all.bash
To compile something make a test program e.g.:
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

and compile with:

8g test.go ;8l test.8 ;./8.out

Version

Hi,

Probably did this before - but administered lost and found computers has made me need this info again.

Version of linux.
cat /proc/version


Gives you:
Linux version 2.6.28-15-generic (buildd@rothera) (gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) ) #52-Ubuntu SMP Wed Sep 9 10:49:34 UTC 2009



And then you need the release info for the distribution.

lsb_release -a


Gives you:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.04
Release: 9.04
Codename: jaunty



And of course uname -a. Which is a start. Would love to hear other tips on determining the state of a box that has previously been abandoned.

Update: Naming of the actual machine and shit as well.

Running hostname should give you the name of the actual machine. Not entirely sure how this works when you have multiple "machines" kinda running off the same physical machine.
user@machine:~$ hostname
machine-name



You can then check this the other way round:
user@machine:~$ host name.domain.tld
ip address .in-addr.arpa domain name pointer name.domain.tld

Sunday, November 15, 2009

list installed packages on debian and uninstall those not correctly removed.

dpkg --get-selections

Will give you a list of packages currently installed on a debian system (possibly works for Ubuntu too?). You may see a few which are listed as "deinstall". They've not uninstalled correctly. To uninstall them use this command I found on the debian mailing lists to purge them:

dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg -P

Friday, November 13, 2009

Turning a Ubuntu install into a Window terminal server dumb terminal

I've written a quick script to term a clean Ubuntu (I'm using 9.04 netbook remix) into a dumb terminal to connect to a windows terminal server.

You can use it like this:

wget http://sgenomics.org/~new/term.tar
tar xvf term.tar
sudo ./termsvr MYTERMINALSERVERNAME MYDOMAINNAME


Under the hood, the script looks like this:

if [ $# -ne 2 ]
then
echo "Usage: `basename $0` "
exit 1
fi

apt-get -y --force-yes remove gnome*
apt-get update
apt-get install rdesktop
cp ./rc.local /etc/rc.local
sed "s/\*SERVERNAME\*/$1/" ./xinitrc > ./xinitrc.fixed0
sed "s/\*DOMAINNAME\*/$2/" ./xinitrc.fixed0 > ./xinitrc.fixed1
cp ./xinitrc.fixed1 /etc/X11/xinit/xinitrc

where xinitrc contains:

#!/bin/bash
# $Xorg: xinitrc.cpp,v 1.3 2000/08/17 19:54:30 cpqbld Exp $

# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)

while [ true ]
do
rdesktop -f *SERVERNAME* -d *DOMAINNAME* -u "" -k en-gb
done

# invoke global X session script
. /etc/X11/Xsession

and rc.local contains:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

startx

exit 0

Upgrading eclipse on Ubuntu

After totally borking my eclipse install I seriously suggest just removing every mention of the damned thing before installing the new version. By removing I mean move to a new dir in /tmp/ of course.

Things to look out for:
/home/user/.eclipse
/home/user/.mozilla/eclipse
/foo/bar/eclipse


Seriously this should be a lot easier. Anyway - the other thing to attempt is exporting your old software update sites list and then importing this into the new install. This should save an ungodly amount of time reinstalling plugins - which vastly outweighs the amount of time installing takes.

Wednesday, November 11, 2009

strings in the n900 firmware

The n900 isn't out yet, but it's firmware is! I ran strings over it and looked at the longer, more interesting strings as follows:

strings RX-51_2009SE_1.2009.42-11_PR_F5_MR0_ARM.bin | awk '{if(length($0) > 50) print $0}' | more

Some interesting finds:

Uses glibc, good to know... GLIBC_2.4

"Major hack here, this needs to be spawned from a proper class"

Always good to know. :)

Skype:

usr/share/locale/fr_FR/LC_MESSAGES/skype-ui.mo

Lots of these:

TMS320C6x COFF Linker Unix v6.0.7 Copyright (c) 1996-2006 Texas Instrument

''C:/users/Prasad/Nokia/CHK_100_V_H264AVC_D_BP_OMAP3430_1_Q

5320C6x COFF Linker Unix v6.0.7 Copyright (c) 1996-2006 Texas Instrumentl

Looks like they are making extensive use of the DSP on the OMAP3430. I guess for accelerating graphics etc. This is good news in terms of functionality, should make the whole experience smoother. But bad news for open source zealots as there's no open source TMS320C6x compiler.

Some familiar apps:

usr/share/doc/osso-fm-transmitter-l10n-cscz/changelog.gz

/usr/share/applications/hildon/chess_startup.desktop
/usr/share/applications/hildon/mahjong_startup.desktop
/usr/share/applications/hildon/osso_lmarbles.desktop
/usr/share/applications/hildon/osso_pdfviewer.desktop
/usr/share/applications/hildon/osso_calculator.desktop
/usr/share/applications/hildon/osso_rss_feed_reader.desktop

What does it use prolog for?!?

usr/share/doc/swi-prolog/changeD

No IPv6?

8Removing IPv6 stuff because it is no longer found in fremantle BUT only ifR

echo "Welcome to your upstart powered internet tablet."

Upstart powered!!

Custom bootloader:

INokia OMAP Loader v1.4.13 (Oct 5 2009) running on %s %s (%s

Wonder if this is the same bootloader they use on the n97...

%s: Checksum mismatch (stored 0x%04x, calc. 0x%04x). Who cares, right?

Yea! Who cares!

Yup, there it is. Stand by for some Linux pleasure.

That's right bitches! Bring on the pleasure.

Monday, November 9, 2009

Sunday, November 8, 2009

Routertech AR7RD ppp interface not coming up

The ppp0 interface on my RouterTech router wasn't coming up on reboot, I have no idea why. To get it to come up I telneted in to the router (login as root, with normal admin password). Then executed the following:

/etc/ppp/ip-up