Home > Archive > PERL Beginners > June 2007 > Perl vs. Java for string manipulation & regex
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Perl vs. Java for string manipulation & regex
|
|
| Jeni Zundel 2007-06-24, 6:59 pm |
| So, recently, I wrote a nice little perl script to go through a
moderately large file (about 400 Meg fixed record length file of rows
that are 1870 characters wide). It runs quite fast; provides
accurate results and I'm happy with it.
My employer doesn't want to use it because it's in perl and he
doesn't think that anyone else in the building knows perl. So, I
decided to work on my java syntax (recently started doing a bit of
java) and use java in order to manipulate the file instead.
My perl script basically does 2 things:
1. selects rows that have .{51}055 in them.
2. based on those selected rows, pull out just a few different
tagged locations as the appropriate data fields. (the file is a VSAM
record and has a ton of valueless crap in it that we don't want.
I've basically rewritten the thing w/ a simple POJO; I'm not using
regex within java because I'm impatient & didn't feel like reading
all of the api documentation on the different objects for using regex
(but I will eventually). In any event, I found that I didn't need
regex in java because I could use a substring command instead.
It is significantly less efficient than the perl script. So my
questions are:
1. Is the java significantly slower than the perl script because I
suck at writing efficient java code or because perl is just really
that much better at string manipulation?
and
2. Does anyone know if the java would be significantly improved if I
make use of regex instead of using substring functions?
thanks in advance,
Jen
| |
| Tom Phoenix 2007-06-24, 6:59 pm |
| On 6/24/07, Jeni Zundel <jenizundel@mac.com> wrote:
> 1. Is the java significantly slower than the perl script because I
> suck at writing efficient java code or because perl is just really
> that much better at string manipulation?
Yes.
If it's important to determine how much of your slowdown is due to a
poor algorithm, how much due to a poor implementation, and how much
due a poorly-designed JVM, you could spend a few w s coding and
benchmarking and testing, of course.
Or you could spend an hour or two trying to convince your manager that
it's sufficient to have a fast Perl program on the job today, because
you have a slow Java program on standby in case we all forget Perl
tomorrow.
> 2. Does anyone know if the java would be significantly improved if I
> make use of regex instead of using substring functions?
Why do you ask this question in a Perl forum? Yes, Perl is great at
string manipulation; but you have your Perl program, you're happy with
it, it's your Java code that you're wondering about improving. If you
ask the Java people, they can give you better answers about improving
your Java code. And they're especially eager when they hear that Java
needs help to compete against Perl.
Cheers!
--Tom Phoenix
Stonehenge Perl Training
| |
| Jenda Krynicky 2007-06-26, 9:59 pm |
| From: "Tom Phoenix" <tom@stonehenge.com>
> On 6/24/07, Jeni Zundel <jenizundel@mac.com> wrote:
Do you think it would take longer to learn the basics of Perl
necessary for that script than it took to reimplement the hundred
lines of well performing Perl as a thousand lines of slow Java?
Visit the boss, show him the two programs printed out (so that he can
compare the length ... that's I guess about all he can understand),
tell him how long did each of them take to write and how long does
each take to process the file and then ask him whether he's really
sure that it's more efficient to waste time with Java or to teach one
more guy some Perl.
[color=darkred]
>
> Why do you ask this question in a Perl forum? Yes, Perl is great at
> string manipulation; but you have your Perl program, you're happy with
> it, it's your Java code that you're wondering about improving. If you
> ask the Java people, they can give you better answers about improving
> your Java code. And they're especially eager when they hear that Java
> needs help to compete against Perl.
Eager? I'd expect them to forget about trying to make it quicker
because they know the've failed to compete many times already and
concentrate on the reasons why Perl should be banned instead.
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
|
|
|
|
|