Thursday, April 4, 2013

Go vs. Scala vs. Erlang

I added Go benchmark to cppa-bechmarks.

Benchmark algorithm is described in libcppa blogpost

I've got results on 2 x Intel(R) Xeon(R) CPU E5620 @ 2.40GHz (16 cores):

Go: 17.87 seconds
Scala: 41.18 seconds
Erlang: 52.98 seconds

PostgreSQL commands

Top 10 largest relations in database:

SELECT relname, relpages FROM pg_class ORDER BY relpages DESC LIMIT 10;

Useful links

Sunday, October 31, 2010

Using Intel© Math Kernel Library in Python

As a way to interact with MKL library from Python is build a shared library from MKL and interface to it using ctypes.

Below is description of the process of creating shared library from MKL.

  1. Download MKL Library from: (for noncommercial use).

  2. Unpack archive and install

  3. Follow this useful article:

Steps for me:

  1. /tools/environment/

  2. cd /tools/builder

  3. $ cat > ring_list

  4. $ make em64t name=mkl4py export=ring_list

  5. Done. Use and /lib/em64t/

MKL online documentation: See "Building Custom Shared Object".

Friday, October 8, 2010

Build OpenSIPS deb package from SVN. Step by step.

If you want to build OpenSIPS package for debian/ubuntu from svn, that this is post for you.

First, checkout OpenSIPS sourses from svn as described here.

For example, to download latest 1.6 branch do:
$ svn co opensips

Enter opensips directory and move debian-directory on top-level:
$ cd opensips
$ ln -s packaging/debian debian

Increase the Debian release number:
$ debchange -i

Finally, build package:
$ debuild -us -uc

Debian packaging utilites can be installed with "sudo aptitude install devscripts build-essential fakeroot".

Saturday, June 19, 2010

Book review: Building Telephony Systems with OpenSIPS 1.6

A few months ago I was asked by Packt Publishing to review the book "Building Telephony Systems with OpenSIPS 1.6" by Flavio E. Goncalves. They sent me a free physical copy of this book. Thanks to them for it.

Before exploring OpenSIPS, you will be taught the basics of SIP. The book will help you install OpenSIPS, and after that you'll be able to work with it. It's good for newbies who want to learn OpenSIPS from scratch.

The main part of the book explains principles needed to create an OpenSIPS routing script for real solutions. You will be able to set up authentication, integrate OpenSIPS with media server, integrate Asterisk Real Time with OpenSIPS, solve NAT traversal problems, configure accounting, and, most importantly, will understand how it works.

Unfortunately, a part of complex issues is not covered in the book. These are, primarily: building high availability solutions with OpenSIPS; SIP presence problems; MediaProxy; etc.

This book is an upgraded version of the "Building Telephony Systems with OpenSER: A step-by-step guide to building a high performance Telephony System" book. Some examples remain actual for Openser, but not for OpenSIPS. Some new OpenSIPS modules are not covered in the book. I've also found several typos in the example scripts. So, if you have problems with the examples in the book, just check the current documentation.

An excellent start to learn OpenSIPS is to read this unique book. The on-line documentation is your friend too.

Friday, January 29, 2010

New book about OpenSIPS!

I'm glad to say that the book "Building Telephony Systems with OpenSIPS 1.6" was released! This book is update of the book about OpenSER. The book was written to answer many questions about building VoIP systems based on the SIP-proxy OpenSIPS.

I'm waiting for delivery of the book to read and review.

Monday, November 30, 2009

C++: compile time square root (sqrt) using templates

This code computes square root in compile time using C++ templates and binary search:

#include <iostream>
using namespace std;

#define MID(a, b) ((a+b)/2)
#define POW(a) (a*a)

template<int res, int l = 1, int r = res>
class SQRT;

template<int res, int r>
class SQRT<res, r, r> {
   static const int value = r;

template <int res, int l, int r>
class SQRT {
   static const int value = SQRT<res, (POW(MID(r, l)) >= res ? l : MID(r, l)+1), (POW(MID(r, l)) >= res ? MID(r, l) : r)>::value;

int main() {
  cout << SQRT<256>::value << endl;
  return 0;

See codepad paste for more information.

Thanks HELLER[i] for idea.

Sunday, November 22, 2009

C++: what is difference between "new T" from "new T()"

Recently I received an interesting question: what difference between "new T" from "new T()" in C++?

Let's look at example:

using namespace std;

class ST {
    ST() {
      cout << "ST constructor executed" << endl;

class T {
    int i;
    ST st;

int main() {
  char mem[1000];
  T *t_ptr;

  memset(mem, 0x0F, sizeof(mem));
  t_ptr = new(mem) T;
  cout << "new T: " << int(t_ptr->i) << endl;

  memset(mem, 0x0F, sizeof(mem));
  t_ptr = new(mem) T();
  cout << "new T(): " << int(t_ptr->i) << endl;

  T t;
  cout << "T t: " << int(t.i) << endl;

  t = T();
  cout << "t = T(): " << int(t.i) << endl;

  return 0;

Output is:

ST constructor executed
new T: 252645135
ST constructor executed
new T(): 0
ST constructor executed
T t: 134515321
ST constructor executed
t = T(): 0

When we use "new T" and "T t" form, t-object default-initialized (in our example via default constructor). In C++ for backward compatibility with C default constructor initialize only non-POD class members. Therefore, called ST constructor and 'i' not initialized.

In case with "new T()" and "t = T()" we get value-initialized object. In our example each class member initialized separately.

For more information read this quotes from the C++ standard (ANSI ISO IEC 14882 2003):
A new-expression that creates an object of type T initializes that object as follows:
  • If the new-initializer is omitted:
    • If T is a (possibly cv-qualified) non-POD class type (or array thereof), the object is default-initialized (8.5). If T is a const-qualified type, the underlying class type shall have a user-declared default constructor.
    • Otherwise, the object created has indeterminate value. If T is a const-qualified type, or a (possibly cv-qualified) POD class type (or array thereof) containing (directly or indirectly) a member of const-qualified type, the program is ill-formed;
  • If the new-initializer is of the form (), the item is value-initialized (8.5);
  • If the new-initializer is of the form (expression-list) and T is a class type, the appropriate constructor is called, using expression-list as the arguments (8.5);
  • If the new-initializer is of the form (expression-list) and T is an arithmetic, enumeration, pointer, or pointer-to-member type and expression-list comprises exactly one expression, then the object is initialized to the (possibly converted) value of the expression (8.5);
  • Otherwise the new-expression is ill-formed.
(5.4.3. New, page 82)

To zero-initialize an object of type T means:
  • if T is a scalar type (3.9), the object is set to the value of 0 (zero) converted to T;
  • if T is a non-union class type, each nonstatic data member and each base-class subobject is zero-initialized;
  • if T is a union type, the object’s first named data member89) is zero-initialized;
  • if T is an array type, each element is zero-initialized;
  • if T is a reference type, no initialization is performed.
To default-initialize an object of type T means:
  • if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
  • if T is an array type, each element is default-initialized;
  • otherwise, the object is zero-initialized.
To value-initialize an object of type T means:
  • if T is a class type (clause 9) with a user-declared constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
  • if T is a non-union class type without a user-declared constructor, then every non-static data member and base-class component of T is value-initialized;
  • if T is an array type, then each element is value-initialized;
  • otherwise, the object is zero-initialized.
An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.

(8.5. Initializers, page 145)

Sunday, November 15, 2009

Python in science

Guido van Rossum wrote a very useful post about python tools in science:
Neopythonic: Python in the Scientific World

I'll research the languages and their libraries for my project work. Perhaps it would be python.