1BRC in COBOL #481
nibrobb
started this conversation in
Show and tell
Replies: 1 comment
-
Hello! I also took COBOL for a spin in 2020. I would like to sit with you at lunch some day! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
I'm not a COBOL programmer by any means. I started learning COBOL during the 2020 COVID-19-crisis after learning about New Jersey's Unemployment Insurance System that still ran in COBOL. That journey took me through IBM Z Xplore (formerly Master the Mainframe) where I learned a lot about mainframes and how to program on them.
Motivation
COBOL is not the hottest language nowadays, but it is still capable. I wanted to see how intuitive a task like 1BRC would be in this language, so I made an attempt and here it is.
Design and implementation
I implemented a very simple, linear, single-threaded solution for this challenge. There are no native hash maps in COBOL, and I didn't quite feel like implementing my own, and using a third-party external library felt like cheating. I just use a TABLE (an array) to store the measurement stations and their values, and linear search for inserting. If I had sorted the input beforehand there is an option to use native binary search (SEARCH ALL) which would likely speed things up a bit.
The main downside of my implementation is the lack of threads. There was no easy way for me to use multi-threading with GnuCOBOL, at least not without writing a heavy C wrapper with pthread-calls for it.
The C wrapper I did write though is merely for a nicer user experience since COBOL traditionally does not take "command line arguments". The C wrapper simply calls a COBOL program with the filename as a PARM (parameter), the same way it would be done on a mainframe.
Source code available from my 1brc-cobol repository.
Performance
Running with the full 1 billion rows on a machine with a Ryzen 9 7950X and 32 GB RAM (which the program is not utilizing at all) the results are as follows
For comparison the baseline Java implementation runs in
Meaning my implementation runs about 12.6 times slower than the baseline 😅
Beta Was this translation helpful? Give feedback.
All reactions