View previous topic :: View next topic
|
Author |
Message |
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 137 Location: brisbane
|
|
|
|
I have a requirement to write a security module for which I need to optimise for performance as far as possible.
some considerations:
- this will only ever run on Z/OS with COBOL 6.2 or higher
- compiler options will include ARCH(12)
- module will execute 10,000+ times per day
- within one transaction unit, module may be executed anywhere from 1 to 100 times
problem 1. How best to initialise a large array of primes.
I need to store the first 10,000 primes (>2) in an array structure (with binary usage). The following example demonstrates one way of doing this (cut down to the first four primes > 2)
Code: |
01 PRIME-NOS PIC X(32) VALUE X'0000000300000005000000070000000B'.
01 FILLER REDEFINES PRIME-NOS OCCURS 4 TIMES.
05 PRIME-NO PIC 99999 USAGE BINARY. |
which seems to work fine, but it suffers somewhat from readability.
is there a better way to present this without compromising performance ? Any compiler directive that might do some of the heavy lifting ?
problem 2. fastest way to unpack a numeric.
I need a fast way to unpack a numeric, for it to be used in a dot product such as :
eg : 7234567 ==> (7,2,3,4,5,6,7) . (n1, n2, n3 .. n7) = 7n1 + 2n2 + ... + 7n7
I could either do something like :
Code: |
05 ws-input-digits pic 9(16).
05 ws-input-digit redefines ws-input-digits occurs 16 times pic 9. |
... or copy to BCD, and then unpack. Which would be more efficient ?
input could be up to PIC 9(16), and could be within an array structure.
as in problem 1, I want the individual digits to have binary usage.
any other tips that can help appreciated. Also, do i need to do anything to exploit ZIIP processing ? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1312 Location: Vilnius, Lithuania
|
|
|
|
You don't write security modules, you use commercial ones that have been thoroughly tested and use approved security standards.
Period. Full stop. End of story! |
|
Back to top |
|
|
steve-myers
Active Member
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
|
|
|
|
prino is 100% correct. Security is awfully difficult.
As for primes. Prepare your list and read them in as required rather than prepare a new list every time. It might not be "faster" in elapsed time, but it will certainly be "faster" in CPU time.
As for preparing a list. A technique called the Sieve of Eratosthenes is the best known, though probably not the fastest. Heck, I did that in the 1960s.
Good luck. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Also, do i need to do anything to exploit ZIIP processing ? |
zIIP processors are for DB2 and Java work, primarily. Certain other workloads will also run on a zIIP, but you generally cannot do anything specifically to exploit the zIIP engine. Nothing you've posted indicates that you're doing anything that could run on a zIIP engine. The work that can run on a zIIP engine will usually run there automatically (even in DB2, not all work is zIIP-eligible). |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10879 Location: italy
|
|
|
|
Quote: |
As for preparing a list. A technique called the Sieve of Eratosthenes is the best known, though probably not the fastest. Heck, I did that in the 1960s. |
no reason to waste time coding,
lists for special numbers are available and can be downloaded
just the first link returned googling with "list of primes"
https://primes.utm.edu/lists/small/10000.txt |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10879 Location: italy
|
|
|
|
as usual people just focus on the lowly technical details
cryptography, security and friends is/are not just code,
there are implications for the organisation, auditing, training, ... ...
but above all legal and certification considerations
and I would never trust an algorithm developed using free forum consultancy |
|
Back to top |
|
|
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 137 Location: brisbane
|
|
|
|
agree with what's been posted above.
for the record, I've finished coding what I was asked to code, and have suggested to the business sponsor that they consider this piece of work as a POC (proof of concept), rather than something that should be moved into production.
By no means a wasted exercise : It's not often I get to combine my passion for number theory with programming. |
|
Back to top |
|
|
|