https://github.com/mgrdich/go_c_benchmarking
Benchmarking Go and C
https://github.com/mgrdich/go_c_benchmarking
Last synced: 5 months ago
JSON representation
Benchmarking Go and C
- Host: GitHub
- URL: https://github.com/mgrdich/go_c_benchmarking
- Owner: Mgrdich
- Created: 2023-09-23T19:09:10.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-25T11:35:51.000Z (over 2 years ago)
- Last Synced: 2025-04-08T15:35:36.014Z (about 1 year ago)
- Language: Makefile
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Benchmarking with C and Go
This is a simple benchmarking app , with scripts and make commands to build any
arbitrary file and benchmark it's speed and performancea
In order to use this
* you must have go `1.21.1` installed
* you must have a C compiler called GCC
if other versions of Go is found please update your `go.mod`a
if other C compiler are found please update your makefile
## Introduction
Two variations of code is here
* one to calculate prime numbers up to N
* one to calculate Sum of N numbers
latter is for compiler optimization example
we benchmark 4 versions
* Native-Go: simple go program
* Go: Go program that uses C
* C: simple C program
* COptimized: optimization flag set during the compilation
## How to use it
### To Build a binary
let's take the case of cgo for prime numbers
* `make build-main-go-prime`
* `go-exec-main-prime` exec file with this name by default , you can edit the makefile to put your custom names all the other make commands are with variables they will pick it up automatically
* `make build-all-prime-exec` this one builds all the prime related exec
### Test and Benchmark it
There is two bash scripts that take care of this one is and they create logs
you can change the log files name by changing the variables for the logs in the makefile
Here is an example
`outCPrimeFile:=output_c_prime`
`outCCompilerPrimeFile:=output_c_compiler_prime`
* `benchmarking.sh` for time it will redirect it to your upper configure file
* `benchmarkMemoryStdOut.sh` to it will redirect to your upper configure file
* `parse-native-data.go` that create an executable to calculate the average over those logs file
to run a particular benchmark
`make benchmark-c-sum` it will run all the benchmarking necessary and create log files
Once the Log files are created
you can run
`make print-c-prime-data` which in its turn will compile the `parse-native-data.go`
if it is not compiled and calculate the averages that those file did generate.
Everything is automated you can customize and and add new stuff to it.