Archive for the ‘Scitech’ Category

Evolution

Saturday, April 18th, 2015

An oftenly used argument by proponents of creationism and intelligent design theories against evolution is why don’t monkeys continue to evolve today”. As a matter of fact, they do: chimpanzees living in the Fongoli savannah of South-East Senegal were observed crafting and using spears for hunting.

Update: Chimps in Uganda look both ways before crossing.

Perl class builders

Monday, June 23rd, 2014

I was more than pelasantly surprised today while benchmarking Moo against Mo, Class::Tiny and Mojo::Base. It turns out the latest version of Moo doesn’t have much of a speed penality when compared to Mo or Mojo::Base. Needless to say it’s two times faster than Class::Tiny. All of this without Class::XSAccessor installed. With it installed it’s on par with Mo, sometimes even faster. If I’d start a new project today I’d probably use either Moo or Mojo::Base.

Rate ct moo mo mb
ct 76799/s -45% -50% -61%
moo 139184/s 81% -10% -29%
mo 154844/s 102% 11% -21%
mb 195491/s 155% 40% 26%

Moo only has features that make sense, such as inheritance, roles plus some safeguards that make sloppy programming a headacke. Some of them are rather annoying, for example fatal warnings, which can be defused by using Moo::Lax. If you want type checking with Moo, there are some documented extensions for that, or you can use Type::Tiny. Moo also provides an easy migration path to Moose and in order to use it you only need to install just about eight non-core dependencies, as opposed to half the CPAN.

Mojo::Base is really minimal, has zero core dependencies and is part of the excellent Mojolicious framework. If you’re already using that you probably don’t need another object builder. The syntax is also Moose-like.

Perl and JSON

Saturday, May 31st, 2014

I like JSON a lot when it comes to seralizing data and REST web services. Perl has very good support for JSON and several libraries to pick from. While selecting the best components for my projects, I have been testing and timing a few Perl modules that produce JSON. These are JSON::PP, which has been in the Perl core since 5.13.9, Mojo::JSON, part of the excellent Mojolicious web framework, JSON::Tiny, a stand-alone adaptation of the latter, JSON::XS, written in C for blazing speed and Cpanel::JSON::XS, a fork of the latter. I also tested JSON:DWIW, an older module also written in C. Let’s see how they perform.

Rate jpp jt mj jdwiw jxs cpjxs
jpp 4437/s -6% -11% -82% -97% -97%
jt 4718/s 6% -5% -81% -97% -97%
mj 4977/s 12% 5% -80% -97% -97%
jdwiw 24917/s 462% 428% 401% -83% -85%
jxs 145479/s 3179% 2983% 2823% 484% -10%
cpjxs 161266/s 3534% 3318% 3140% 547% 11%

If you don’t want to bother, JSON::MaybeXS is a wrapper module that automatically selects the best out of three of them and can also operate like the core JSON, so you only have to change your use statement and leave the rest of your code untouched. JSON::PP, JSON:DWIW and the XS modules are packed with features, while Mojo::JSON and JSON::Tiny are minimalistic libraries and only produce inline compacted JSON suitable for machine consumption.

Each

Friday, April 4th, 2014

Avoid it like the plague.

Goodbye Linux

Sunday, February 16th, 2014

As the remaining non-systemd major Linux distributions are moving to systemd, I am more likely to refrain from further Linux usage whenever I am making my own decisions.

I am currently using Ubuntu LTS on the desktop. 14.04 would most likely be the last LTS version to use upstart, as Debian is switching to systemd and Ubuntu people have decided to follow upstream.

I would happily use Gentoo if it wasn’t an ever moving target, requring me to compile everything by hand every time. In fact I shall give it a shot anyhow, maybe it does indeed work for me. OpenRC is a good and correct approach to system init because it does not overdo everything like systemd does. I would have preferred runit, but anything else other than systemd is fine. Why? Because systemd is broken by design.

SuSE has been struggling to migrate everything to systemd since version 12.1. Fast forward three years. We are now at 13.1 and there are still problems with it.

So it looks like I am heading towards a BSD desktop after all. On servers I’ve been already running FreeBSD for the last ten years or so.

Addendum:

I am not going to use Gentoo. The install is too tendious and it requires building everything from source, including the base system. By contrast, all the BSDs offer a fully functional and very well integrated base operating system that’s easy to install. With pkgng you also get access to over 20k packages that are rebuilt weekly.

Upstart is sometimes even worse. If you try to disable a service you end up messing with scripts. Override files? You must be kidding me. Whatever happened to symlinks? What I mean is a single symlink for every service, runit style, not multiple symlinks like sysvinit uses. Or a single config file, like rcng uses. At least systemd provides a single command that allows you to enable, disable, start, stop, list services and more. Its switches are long and not always intuitive, but at least it does have builtin help. OpenRC has three of them, yet it’s still a lot better than messing with scripts and override files.

Perl6 syntax

Saturday, January 25th, 2014

You hated Perl5 because of sigil abundance? Or because of it’s dereference syntax? Good. Because Perl6 now has twigils and changes the C-style operator semantics. It now looks less like C and more like insanity. Here’s the big picture.

“Multiple exclamation marks,” he went on, shaking his head, “are a sure sign of a diseased mind.” – Terry Pratchett

Perl6 on MoarVM

Friday, January 24th, 2014

The other good news for today is that we now have the first Rakudo Perl6 compiler that has support for building and running on MoarVM plus some important improvements on the JVM.

FreeBSD 10R

Friday, January 24th, 2014

I faied to mention that FreeBSD 10 was out since 31 January. Here’s the release notes. It includes many new changes, for example unbound, clang and pkg being the default resolver, compiler and package manager, respectively, or other more subtile goodies such as filename completion in sh(1). Yay! BIND, GCC and the old package manager are out. Reasons for this include BIND10 being rewritten in C++ and Python, new versions of GCC being distributed under the more restrictive GPLv3 and the old package manager being old.

Comparing arrays

Thursday, November 21st, 2013

Here are four ways to compare two arrays in Perl:

I won’t cover Array::Compare because it depends on Moose and only compares two arrays. Why in the world would anyone use Moose to achieve such a trivial task is beyond me. There is also Data::Compare, which can compare deep structures, just like Test::Deep.

Rate eq_deeply match_smart smartmatch array_comp
eq_deeply 3021/s -92% -97% -99%
match_smart 38824/s 1185% -65% -87%
smartmatch 110476/s 3557% 185% -64%
array_comp 305302/s 10007% 686% 176%

The eq_deeply method turned out to be the slowest, but keep in mind that it’s also very powerful. It does not flatten deep arrays or hases and can accurately compare all sorts of data, not just flat arrays. I’ve been even able to compare code references with Test::Deep. The array_comp method is blazingly fast but does no checking and will only work with flat arrays. If you give it a nested structure to churn it would fail to produce an accurate result. Smartmatch and match::smart are somewhere in between. They should be used as general purpose tools to match simple data as described in the documentation. Matching nested structures with them is probably not so smart – use Test::Deep or Data::Compare instead.

Perl class builders

Saturday, October 26th, 2013

The beauty of Perl is choiceSome would argue there’s too much of it. When it comes to advanced OO features, Perl has many options to choose from. None of them are actually in the core but are available as third-party modules from CPAN. This will hopefully get fixed in the future.

One such an OO framework that is really popular among Perl developers is Moose. The problem with Moose is that it does everything and it also depends on many outside modules. But Moose led to some interesting experiments, one of which is Mo. Along with Mo, I have evaluated another minimal OO class builder for Perl, named Class::Tiny, which is in fact an Object::Tiny workalike. Confused already?

I like both class builders because they are minimal require no outside modules, so I had to test which one of them offered more useful features while still being fast. The code that I used to do this is available here. For the second test everything in the main package was wrapped inside a loop that ran 1e6 times. Current versions (Mo 0.37 and Class::Tiny 0.011) were tested on an Athlon 64 x2 box running at 1 Ghz with two gigs of RAM. Here are the results:

Mo Class::Tiny
1 run 1e6 runs 1 run 1e6 runs
real 0m0.016s
user 0m0.012s
sys 0m0.004s
real 0m20.719s
user 0m9.013s
sys 0m4.492s
real 0m0.033s
user 0m0.028s
sys 0m0.000s
real 0m28.745s
user 0m17.093s
sys 0m4.816s

As you can see, Mo turned out to be 51% faster in single runs and 28% faster when it ran multiple times. It also has some additional features, without enfocing them on the user – they have to be explicitly enabled. Mo also provides an easier and more obvious upgrade path to Moo, Mouse or Moose. It does not, however, provide multiple inheritance or a destroy method. If you need them, use Class::Tiny or Moo. Also, please keep in mind that benchmarking Mo against Class::Tiny is rather pointless because their feature set is different.

I repeated the test using Benchmark, this time appending to my favourite file descriptor. Mo came out faster by almost 50%. When writing to standard output the results are roughly the same as above. I also tested Mojo::Base, Object::Simple and Object::Tiny. They are roughly on par with one another and a tad faster than Mo, but the difference is only about 16%. Object::Tiny came out the fastest of the bunch.