Showing posts with label fpc. Show all posts
Showing posts with label fpc. Show all posts

Saturday, February 11, 2012

C++ vs FPC vs Java vs C# benchmarking

There were a lot of microbenchmarks etc. in the net to prove which solution is better -- Java or .NET, yet I decided to write a simple yet useful program (An image processing tool we use in developing games for OpenGL ES devices) and port it to several languages. I've put it into a public repo under

https://github.com/exhu/alimg

My results were so that the fastest solution under Linux was in Java (7 secs), then C++  and FreePascal (11-10 secs average). Yes, C++ slower here, of course you can optimize C++ into unreadable code and get most of the hardware, but the code will be unmaintainable and cryptic, while now it's a balanced solution, and still Java sources are the most user-friendly.

Mono was 4 times slower than Java under Linux (28-30 secs), and .NET was as fast as Java under Windows XP 32-bit under VirtualBox (both do the job for about 17 secs), yet the FreePascal version was even faster than both of them (10 secs -- about the same speed in the VirtualBox as on the real Linux).


Linux:
1) Java (OpenJDK 6)
2) C++, FPC
4) Mono

Windows (under Linux VirtualBox):
1) FPC
2) Java (Oracle Java 6), .NET 4

Assume C++ version would be the fastest under Windows too.

I also need to note that .NET 4 offline installation was rather hard to complete under Windows XP 32-bit SP2, it required several downloads for Windows Installer, Windows Imaging and took 20 minutes to install. Meanwhile Java offline installer (~20 megs) was easy and fast and did not require restarting the OS.


To sum up I would pick FPC for native small to medium applications and Java for cross-platform medium to complex applications. Although Java is surprisingly fast on netbooks it's too memory hungry.

Thursday, December 22, 2011

Memory Leaks

Nice article on the topic: http://www.delphibasics.co.uk/Article.asp?Name=Memory

By the way, Pascal's manner of declaring variables in a single place ('var section') seems unproductive for C/C++ fans but it is very helpful in tracking resources (class references) -- look for the known block in a function and check if all of the references are properly freed on return.

Saturday, December 17, 2011

Lazarus problem solution for Ubuntu 11.10

" Lazarus applications have problems to run on latest Ubuntu 11.10 where the reason is new Taskbar menu and scrollbar.

To get application running like on older Ubuntu we have to remove some functionality from Ubuntu using by this command:

sudo apt-get remove appmenu-gtk3 appmenu-gtk appmenu-qt
liboverlay-scrollbar-0.2-0 "

http://62.166.198.202/view.php?id=20520

Sunday, December 11, 2011

FreePascal experience

Tried FPC 2.4.4 recently, what I must say, Lazarus and console fpide are unusable under Ubuntu 11.10 and MacOSX -- crash all the time, no debugger support and strange GUI bugs, although I have not tried them under Windows.

However, the big POSITIVE side is that the compiler (FPC) is a lightning fast one and easy to install at any platform. It's even faster than javac. I'm really impressed. And GDB understands well pascal programs, tried to debug and it's amazingly feature rich. The language is plain simple and you can easily program in any decent text editor. I really enjoyed playing around with it. The generated applications are lightweight like in good old times, native, fast, not so hungry for memory and cpu resources. Also FPCMAKE is a good tool if you plan to develop a more or less complex application.

FPDOC tool is not what I like to use (it requires documentation not in the source comments but in a separate xml file), better to pick pasdoc (http://pasdoc.sipsolutions.net/) for those who used to javadoc and doxygen.


As for the Pascal programs I've used -- they are not pretty stable, I think it's the fault of the poor memory management strategy applied. It's better to use reference-counting techniques like in GNUstep/Cocoa than TComponent's sole ownership and dangling pointers.

Playing with the compiler I have tried to implement a base class to do that counting and one more to track weak references. It was a success, so it's not the language fault but the programmers who use it, because my solution looks good and I plan to publish a library on GitHub if I ever program in FP.

One more deficiency is the lack of Unicode strings support in OS calls, e.g. for file names on Windows. Although it's no problem under Linux and/or MacOSX.

Generally FPC is a great tool, and there are a lot of useful libraries to make life easy.

Sunday, December 4, 2011

FreePascal status

Unicode is supported by LCL (Lazarus) via UTF-8. There are several functions to convert from system encoding strings (codepage on Windows) to utf-8 strings.

http://wiki.freepascal.org/LCL_Unicode_Support

According to the docs, fpc supports MacOSX 32 and 64-bit, iOS targets.http://wiki.freepascal.org/LCL_Unicode_Support