views:

304

answers:

5

How does the processing overhead of the length() function in REXX change with the length of the string?


Update: I'm using:

  • uni-REXX (R) Version 297t
  • Open-REXX (TM) Copyright (C) iX Corporation 1989-2002. All rights reserved.
+2  A: 

I'm not sure. I've written some Rexx in my days but I've never had performance trouble with the length() function. The way this scales is probably even depending on your implementation of the Rexx parser.

I'd write a Rexx script that times 10.000 calls of "length()" on a 10-character sting, then on a 100 character string, and then on a 1000 character string.

Plotting the resulting times in a graph would give you an approximation on how performance decreases.

Having said all this, my guess is that performance decrease is at most linear, as in O(n). (See http://en.wikipedia.org/wiki/Big_O_notation)

Rolf
+2  A: 

It depends entirely on the implementation. Do you mean REXX for OS/2, REXX for z/VM, REXX for z/OS, OOREXX for Windows, REXX/400 or Regina?

Nothing in the REXX language specs out of IBM dictate how the function is implemented under the covers, it could be O(N) if you scan the string or O(1) if the length is stored with the string somewhere.

If it's really important, best to test with benchmarking code to see if the length makes a difference.

paxdiablo
+1  A: 

It's language implementation specific. It was a long time since I wrote any REXX now, in fact I wrote AREXX (the Amiga implementation) and it was 15 years ago. :-)

You can write your own test routine. Generate strings of increasing length and measure the time it takes to get length() using a high performance timer. If you store the times and string lengths in a text file based comma separated table you can then plot it using gnuplot. And then you'll see very clearly how it scales.

Edit: I should have checked Rolf's answer first since he wrote more or less the same thing. :-)

DeletedAccount
+1  A: 

The overhead is 0. The length is stored in a descriptor.

Neil Milsted Author of uni-REXX (no kidding).

A: 

I can speak for the IBM Mainframe versions, the Classic Rexx version for OS/2, and any of the Object Rexx implementations. The length is stored in the string descriptor, so the overhead is independent of the string length.