-
String.intern() – there are better ways
I don’t want to write a “considered harmful” article (because they are harmful), but after experimenting with different solutions I do have a strong opinion that there almost no reason to use String.intern() in Java. But let us proceed step-by-step. First of all, what does String.intern() do? Go read the Javadoc for it and also…
-
Parsing pcap files with Perl
Recently I was reading the blogpost on the BrekingPoint labs log about parsing pcap files with Perl and I immediately said to myself: it is impossible that there isn’t a module on CPAN, because Perl is great. Turns out I was right, there is Net::TcpDumpLog which can be combined with the NetPacket family of modules…
-
Computing the last digit of b^e efficiently
Geek PSA: Yesterday was PI day (3.14, get it?). Lets celebrate with this spiked math comic: Last week I saw the following problem which peaked my interest: Compute the last (decimal) digit of 2 raised to the power e where e might be very large. We assume that we are talking about positive, integer exponents…
-
In praise of Regexp::Assemble
…and of the Perl modules in general. I had the following problem: Given a list of 16 character alphanumeric IDs, find all the lines from a large-ish (~6GB) logfile which contain at least one of the IDs. The naive approach was to construct a big regular expression like W(QID1E|QID2E|QID3E…)W and match it against every line…
-
Java import statement gotcha
There is a lot of debate on the intertubes if one should or shouldn’t use wildcard imports. I’m mostly indifferent to the discussion (mainly because all the package references are resolved compile time – so there is no performance overhead – and because today’s IDE’s contain a lot of smarts to help you figure out…
-
Carving out files with Perl
I’ve had to use this trick a couple of times the last few years, so I decided that I might as well document it: If you have an image of a storage media (like an SD card or CD/DVD) which you can not mount (either because the filesystem is hosed – that’s a technical term…
-
Splitting hairs^H^H^H^H^H strings with Java
Offtopic: where does ^H come from? (since I too found it only recently) – from the source of all wisdom – Wikipedia :-p Pressing the backspace key on a computer terminal would generate the ASCII code 08, BS or Backspace, which would delete the preceding character. That control code could also be accessed by pressing…
-
Choosing a Java profiler
Recently I’ve been looking around for a Java profiler (since the two things you need for a successful performance tuning session are good data and clear targets). I’ll share the notes about my findings in the hope that they might be useful for someone. Quick disclaimer: don’t believe everything you read on the Internet! These…
-
Don’t Yield to pressure?
or: does Thread.yield have its place in todays Java programs? I was profiling a rather old legacy codebase (since the first rule of performance optimization is “profile it” with the close second of “have clear goals in mind” – but that’s an other post) and – after optimizing the first few hotspots, Thread.yield appeared at…
-
Using TarInputStream from Java
Recently I had to parse trough a bunch of logs, scattered in subdirectories and different types of archives (tar, bz and gz). My first thought was of course Perl (since it is the language for parsing quasi-freeform text), however I didn’t have “streaming” implementation for the archive modules, which in my case was very important,…