Skip to content

Commit

Permalink
working cobol version
Browse files Browse the repository at this point in the history
  • Loading branch information
rivnakm committed Aug 26, 2023
1 parent 11dc95c commit 36f9816
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"vlanguage.vscode-vlang",
"ms-dotnettools.csdevkit",
"fortran-lang.linter-gfortran",
"adacore.ada"
"adacore.ada",
"ms-vscode.makefile-tools",
"broadcommfd.cobol-language-support"
]
}
}
Expand Down
3 changes: 3 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ RUN apt update && apt install --no-install-recommends -y clang
# C++
RUN apt update && apt install --no-install-recommends -y meson

# COBOL
RUN apt update && apt install --no-install-recommends -y gnucobol

# Cython
RUN apt update && apt install --no-install-recommends -y cython3 python3-dev

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![C](https://img.shields.io/badge/c-%2300599C.svg?style=for-the-badge&logo=c&logoColor=white)
![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=for-the-badge&logo=c%2B%2B&logoColor=white)
![C#](https://img.shields.io/badge/c%23-%23239120.svg?style=for-the-badge&logo=.net&logoColor=white)
![COBOL](https://img.shields.io/badge/cobol-%23333333.svg?style=for-the-badge)
![Cython](https://img.shields.io/badge/cython-ffffff?style=for-the-badge&logo=python&logoColor=3670A0)
![D](https://img.shields.io/badge/d-%2398312A.svg?style=for-the-badge&logo=d&logoColor=white)
![Dart](https://img.shields.io/badge/dart-%230175C2.svg?style=for-the-badge&logo=dart&logoColor=white)
Expand Down Expand Up @@ -58,6 +59,8 @@ by shifting half of the work onto random argument parsing libraries rather than
- Ninja
- C#
- .NET 7.0 SDK
- COBOL
- GnuCOBOL
- Cython
- Python headers
- D
Expand Down Expand Up @@ -132,6 +135,14 @@ cd csharp/
dotnet run
```

### Cobol

```sh
cd cobol/
make
./game_of_life
```

### Cython

```sh
Expand Down Expand Up @@ -300,7 +311,7 @@ You can also specify how many iterations to run the benchmark (default 5), avera
python benchmark.py --iterations 5
```

The set of languages to run in the benchmark can also be set. NOTE: Some languages, e.g. bash, powershell, are disabled by default for performance reasons. The default set is "ada,c,cpp,csharp,d,dart,fortran,fsharp,go,haskell,java,julia,lua,nim,perl,python,ruby,rust,typescript,vb,zig"
The set of languages to run in the benchmark can also be set. NOTE: Some languages, e.g. bash, powershell, are disabled by default for performance reasons. The default set is "ada,c,cpp,csharp,cobol,d,dart,fortran,fsharp,go,haskell,java,julia,lua,nim,perl,python,ruby,rust,typescript,vb,zig"

```sh
python benchmark.py --languages c,cpp,rust
Expand Down
6 changes: 6 additions & 0 deletions benchmark_setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"runCmd": "./csharp/bin/Release/net7.0/GameOfLife",
"enabled": true
},
{
"properName": "COBOL",
"shortName": "cobol",
"runCmd": "./cobol/game-of-life",
"enabled": true
},
{
"properName": "Cython",
"shortName": "cython",
Expand Down
1 change: 1 addition & 0 deletions cobol/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
game-of-life
5 changes: 5 additions & 0 deletions cobol/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
cobc -x -O3 -o game-of-life game.cob

clean:
rm -f game-of-life
105 changes: 105 additions & 0 deletions cobol/game.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. GAME-OF-LIFE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HEIGHT PIC 9(2) VALUE 50.
01 WIDTH PIC 9(3) VALUE 100.
01 BOARD-SIZE PIC 9(4) VALUE 5000.
01 GENERATIONS PIC 9(3) VALUE 500.
01 CELLS-TABLE.
05 CELLS-A PIC 9 OCCURS 5000 TIMES.
05 CELLS-B PIC 9 OCCURS 5000 TIMES.
01 SEED PIC 9(9) VALUE 123456789.
01 RAND PIC 9(9).
01 F PIC 9(4).
01 G PIC 9(4).
01 I PIC 9(3).
01 J PIC 9(3).
01 N PIC 9(3).
01 M PIC 9(3).
01 K PIC 9(3).
01 L PIC 9(3).
01 RESULT PIC 9.
01 CELL PIC 9.
01 ADJ PIC 9.
01 ESC PIC X VALUE X"1B".

PROCEDURE DIVISION.
PERFORM VARYING F FROM 1 BY 1 UNTIL F > BOARD-SIZE
COMPUTE SEED = SEED * 4848 + 1
COMPUTE RAND = FUNCTION MOD(SEED, 90) + 2

IF RAND > 50
MOVE 1 TO CELLS-A(F)
ELSE
MOVE 0 TO CELLS-A(F)
END-IF
END-PERFORM.

PERFORM VARYING F FROM 1 BY 1 UNTIL F > GENERATIONS
PERFORM VARYING I FROM 1 BY 1 UNTIL I > HEIGHT
PERFORM VARYING J FROM 1 BY 1 UNTIL J > WIDTH
IF CELLS-A((I - 1) * WIDTH + J) = 1
DISPLAY "██" WITH NO ADVANCING
ELSE
DISPLAY " " WITH NO ADVANCING
END-IF
END-PERFORM
DISPLAY " "
END-PERFORM

DISPLAY ESC "[50A" WITH NO ADVANCING

PERFORM VARYING G FROM 1 BY 1 UNTIL G > BOARD-SIZE
MOVE CELLS-A(G) TO CELLS-B(G)
END-PERFORM

PERFORM VARYING I FROM 1 BY 1 UNTIL I > HEIGHT
PERFORM VARYING J FROM 1 BY 1 UNTIL J > WIDTH
MOVE I TO N
MOVE J TO M
PERFORM GET-CELL
MOVE RESULT TO CELL
MOVE 0 TO ADJ

PERFORM COMPUTE-ADJACENT

IF CELL = 1
IF ADJ < 2
MOVE 0 TO CELL
END-IF
IF ADJ > 3
MOVE 0 TO CELL
END-IF
ELSE
IF ADJ = 3
MOVE 1 TO CELL
END-IF
END-IF

MOVE CELL TO CELLS-A((I - 1) * WIDTH + J)
END-PERFORM
END-PERFORM
END-PERFORM.
STOP RUN.

GET-CELL.
IF N >= 1 AND M >= 1 AND N <= HEIGHT AND M <= WIDTH
MOVE CELLS-B((N - 1) * WIDTH + M) TO RESULT
ELSE
MOVE 0 TO RESULT
END-IF.

COMPUTE-ADJACENT.
PERFORM VARYING K FROM 0 BY 1 UNTIL K > 2
PERFORM VARYING L FROM 0 BY 1 UNTIL L > 2
IF K <> 1 OR L <> 1
COMPUTE N = I + K - 1
COMPUTE M = J + L - 1
PERFORM GET-CELL
IF RESULT = 1
COMPUTE ADJ = ADJ + 1
END-IF
END-IF
END-PERFORM
END-PERFORM.

0 comments on commit 36f9816

Please sign in to comment.