Skip to content

Commit

Permalink
Merge branch 'main' into babashka
Browse files Browse the repository at this point in the history
  • Loading branch information
bddicken authored Dec 18, 2024
2 parents 65c9164 + e09389e commit b0b4742
Show file tree
Hide file tree
Showing 83 changed files with 3,334 additions and 196 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/hello-world.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Hello World

on:
push:
branches:
- '**'
pull_request:
branches:
- main

jobs:
hello-world:
runs-on: macos-latest

steps:
- run: echo LOCAL ${{ env.LOCAL }}

- name: Checkout repository
uses: actions/checkout@v4

- name: Setup LLVM
uses: ZhongRuoyu/setup-llvm@v0
with:
llvm-version: 17

- name: Setup GraalVM w/ native-image
uses: graalvm/setup-graalvm@v1
with:
java-version: '23'
distribution: 'graalvm-community'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@ac5052cad8ffe5039f26968da4b4a0ca88d00971
with:
cli: latest
bb: latest
no-auth: ${{ env.LOCAL == 'true' }}

- name: Setup Fortran
uses: fortran-lang/setup-fortran@v1
id: setup-fortran
with:
compiler: gcc
version: '13'

# - name: Setup Haskell
# uses: haskell-actions/setup@v2

# - name: Setup zig
# uses: mlugg/setup-zig@v1

- name: Setup Dart
uses: dart-lang/setup-dart@v1

- name: Set up PyPy
uses: actions/setup-python@v5
with:
python-version: 'pypy3.10'

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.11.0'

- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.1.34'

- name: Cache Homebrew
uses: actions/cache@v4
with:
path: |
/opt/Homebrew
/opt/Caskroom
key: ${{ runner.os }}-brew-${{ hashFiles('Brewfile') }}
restore-keys: |
${{ runner.os }}-brew-
- name: Brew Install hyperfine and various languages and tools
run: brew bundle --file=Brewfile

- name: Compile Hello World programs
run: |
cd hello-world
bash ../compile.sh
continue-on-error: true

- name: Run Hello World benchmarks
run: |
cd hello-world
bash ../run.sh
continue-on-error: true
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@

*.class
code
.idea/
*.user
*.o
*.ali
.aider*
.env
.env
node_modules/
target/
build/
out/
dist/
*.log
*.aux
*.bbl
*.blg
20 changes: 20 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
brew "python@3.13"
brew "rust"
brew "go"
brew "ruby"
brew "zig"
brew "hyperfine"
brew "lua"
brew "luajit"
brew "odin"
brew "elixir"
brew "chezscheme"
brew "mawk"
brew "gnucobol"
brew "vlang"
brew "dart-sdk"
cask "dotnet-sdk"
brew "julia"
brew "haskell-stack"
brew "kotlin"
cask "kotlin-native"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ You are also welcome to add new top-level benchmarks dirs

# Available Benchmarks

### [hello-world](./hello-world/README.md)

### [loops](./loops/README.md)

### [fibonacci](./fibonacci/README.md)
Expand Down
5 changes: 5 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ rm c/code
rm cpp/code
rm go/code
rm jvm/code.class
rm scala/code scala/code-native
rm -r rust/target
rm -rf kotlin/code.jar
rm kotlin/code.kexe
Expand All @@ -21,8 +22,12 @@ rm zig/code
rm lua/code
rm -f swift/code
rm haxe/code.jar
rm -rf csharp/bin
rm -rf csharp/obj
rm -rf csharp/code-aot
rm -rf csharp/code
rm -rf fsharp/bin
rm -rf fsharp/obj
rm -rf fsharp/code-aot
rm -rf fsharp/code
rm haskell/code haskell/*.hi haskell/*.o
Expand Down
88 changes: 50 additions & 38 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
function compile {
if [ -d ${1} ]; then
echo ""
echo "Compiling $1"
${2} 2> /dev/null
result=$?
if [ $result -eq 1 ]; then
echo "Failed to compile ${1} with command: ${2}"
fi
fi
}

clang -O3 c/code.c -o c/code
clang++ -std=c++23 -march=native -O3 -Ofast -o cpp/code cpp/code.cpp
go build -ldflags "-s -w" -o go/code go/code.go
javac jvm/code.java
bun build --bytecode --compile js/code.js --outfile js/bun
native-image -O3 jvm.code
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build --manifest-path rust/Cargo.toml --release
cargo build --manifest-path rust/Cargo.toml --release
kotlinc -include-runtime kotlin/code.kt -d kotlin/code.jar
kotlinc-native kotlin/code.kt -o kotlin/code -opt
dart compile exe dart/code.dart -o dart/code --target-os=macos
cd inko && inko build --opt=aggressive code.inko -o code && cd ..
nim c -d:danger --opt:speed -d:passC -x:off -a:off nim/code.nim
nim -d:release --threads:off --stackTrace:off --lineTrace:off --opt:speed -x:off -o:nim/code c nim/code.nim
sbcl --noinform --non-interactive --load "common-lisp/code.lisp" --build
fpc -O3 fpc/code.pas
crystal build -o crystal/code --release crystal/code.cr
scala-cli --power package scala/code.scala -f -o scala/code
ldc2 -O3 -release -boundscheck=off -mcpu=native flto=thin d/code.d
odin build odin/code.odin -o:speed -file -out:odin/code
clang -O3 -framework Foundation objc/code.m -o objc/code
gfortran -O3 fortran/code.f90 -o fortran/code
zig build-exe -O ReleaseFast -femit-bin=zig/code zig/code.zig
luajit -b lua/code.lua lua/code
swiftc -O -parse-as-library -Xcc -funroll-loops -Xcc -march=native -Xcc -ftree-vectorize -Xcc -ffast-math swift/code.swift -o swift/code
dotnet publish csharp -o csharp/code
dotnet publish fsharp -o fsharp/code
ghc -O2 -fllvm haskell/code.hs -o haskell/code || { echo "ghc: cannot compile with llvm backend; fallback to use default backend"; ghc -O2 haskell/code.hs -o haskell/code; }
v -prod -cc clang -d no_backtrace -gc none -o v/code v/code.v
emojicodec emojicode/code.emojic
echo '(compile-program "chez/code.ss")' | chez --optimize-level 3 -q
(cd clojure && mkdir -p classes && clojure -Sdeps '{:paths ["."]}' -M -e "(compile 'code)")
cobc -I /opt/homebrew/include/ -O -O2 -O3 -Os -x -o cobol/main cobol/main.cbl
lake build --dir lean4
#dotnet publish fsharp -o fsharp/code-aot /p:PublishAot=true /p:OptimizationPreference=Speed
# haxe --class-path haxe -main Code --jvm haxe/code.jar # was getting errors running `haxelib install hxjava`
#dotnet publish csharp -o csharp/code-aot /p:PublishAot=true /p:OptimizationPreference=Speed
#gnatmake -O3 -gnat2022 -gnatp -flto ada/code.adb -D ada -o ada/code
compile 'c' 'clang -O3 c/code.c -o c/code'
compile 'cpp' 'clang++ -std=c++23 -march=native -O3 -Ofast -o cpp/code cpp/code.cpp'
compile 'go' 'go build -ldflags "-s -w" -o go/code go/code.go'
compile 'jvm' 'javac jvm/code.java'
compile 'js' 'bun build --bytecode --compile js/code.js --outfile js/bun'
compile 'jvm' 'native-image -O3 jvm.code'
compile 'rust' 'RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build --manifest-path rust/Cargo.toml --release'
compile 'rust' 'cargo build --manifest-path rust/Cargo.toml --release'
compile 'kotlin' 'kotlinc -include-runtime kotlin/code.kt -d kotlin/code.jar'
compile 'kotlin' 'kotlinc-native kotlin/code.kt -o kotlin/code -opt'
compile 'dart' 'dart compile exe dart/code.dart -o dart/code --target-os=macos'
compile 'inko' 'cd inko && inko build --opt=aggressive code.inko -o code && cd ..'
compile 'nim' 'nim c -d:danger --opt:speed -d:passC -x:off -a:off nim/code.nim'
compile 'nim' 'nim -d:release --threads:off --stackTrace:off --lineTrace:off --opt:speed -x:off -o:nim/code c nim/code.nim'
compile 'sbcl' 'sbcl --noinform --non-interactive --load "common-lisp/code.lisp" --build'
compile 'fpc' 'fpc -O3 fpc/code.pas'
compile 'crystal' 'crystal build -o crystal/code --release crystal/code.cr'
compile 'scala' 'scala-cli --power package scala/code.scala -f -o scala/code'
compile 'scala' 'scala-cli --power package --native scala/code.scala -f -o scala/code-native --native-mode release-full'
compile 'ldc2' 'ldc2 -O3 -release -boundscheck=off -mcpu=native flto=thin d/code.d'
compile 'odin' 'odin build odin/code.odin -o:speed -file -out:odin/code'
compile 'objc' 'clang -O3 -framework Foundation objc/code.m -o objc/code'
compile 'fortran' 'gfortran -O3 fortran/code.f90 -o fortran/code'
compile 'zig' 'zig build-exe -O ReleaseFast -femit-bin=zig/code zig/code.zig'
compile 'lua' 'luajit -b lua/code.lua lua/code'
compile 'swift' 'swiftc -O -parse-as-library -Xcc -funroll-loops -Xcc -march=native -Xcc -ftree-vectorize -Xcc -ffast-math swift/code.swift -o swift/code'
compile 'csharp' 'dotnet publish csharp -o csharp/code'
compile 'fsharp' 'dotnet publish fsharp -o fsharp/code'
compile 'haskell' 'ghc -O2 -fllvm haskell/code.hs -o haskell/code || { echo "ghc: cannot compile with llvm backend; fallback to use default backend"; ghc -O2 haskell/code.hs -o haskell/code; }'
compile 'v' 'v -prod -cc clang -d no_backtrace -gc none -o v/code v/code.v'
compile 'emojicode' 'emojicodec emojicode/code.emojic'
compile 'chez' "echo '(compile-program \"chez/code.ss\")' | chez --optimize-level 3 -q"
compile 'clojure' "(cd clojure && mkdir -p classes && clojure -Sdeps '{:paths [\".\"]}' -M -e \"(compile 'code)\")"
compile 'cobol' 'cobc -I /opt/homebrew/include/ -O -O2 -O3 -Os -x -o cobol/main cobol/main.cbl'
compile 'lean4' 'lake build --dir lean4 '
# compile 'fsharp' 'dotnet publish fsharp -o fsharp/code-aot /p:PublishAot=true /p:OptimizationPreference=Speed'
# compile 'java' 'haxe --class-path haxe -main Code --jvm haxe/code.jar # was getting errors running `haxelib install hxjava`'
# compile 'csharp' 'dotnet publish csharp -o csharp/code-aot /p:PublishAot=true /p:OptimizationPreference=Speed'
# compile 'ada' 'gnatmake -O3 -gnat2022 -gnatp -flto ada/code.adb -D ada -o ada/code'
18 changes: 18 additions & 0 deletions hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Hello World

This program simply prints “Hello, World!” to standard output and then exits.
It serves as a baseline, trivial test with minimal overhead to ensure that the environment is set up and functioning correctly.

Below is the reference C program.
All languages must do the same work and meet these requirements:
- Print exactly one line of text: “Hello, World!\n”
- Exit with a successful status code.

```C
#include <stdio.h>

int main() {
printf("Hello, World!\n"); // All implementations must print "Hello, World!" followed by a newline character.
return 0; // All implementations must terminate successfully.
}
```
4 changes: 4 additions & 0 deletions hello-world/awk/code.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN {
delete ARGV[1]
print "Hello, World!"
}
6 changes: 6 additions & 0 deletions hello-world/c/code.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}
5 changes: 5 additions & 0 deletions hello-world/chez/code.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!chezscheme
(import (chezscheme))

(display "Hello, World!")
(newline)
5 changes: 5 additions & 0 deletions hello-world/clojure/code.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns code
(:gen-class))

(defn -main [& args]
(println "Hello, world!"))
6 changes: 6 additions & 0 deletions hello-world/cobol/main.cbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. HelloWorld.

PROCEDURE DIVISION.
DISPLAY "Hello, World!"
STOP RUN.
6 changes: 6 additions & 0 deletions hello-world/cpp/code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
1 change: 1 addition & 0 deletions hello-world/csharp/code.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Console.WriteLine("Hello, World!");
10 changes: 10 additions & 0 deletions hello-world/csharp/code.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions hello-world/dart/code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'dart:math';

void main(List<String> args) {
print("Hello, World!");
}
1 change: 1 addition & 0 deletions hello-world/elixir/bench.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IO.puts("Hello, World!")
3 changes: 3 additions & 0 deletions hello-world/fortran/code.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program main
print *, "Hello, World!"
end program main
6 changes: 6 additions & 0 deletions hello-world/fsharp/code.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open System

[<EntryPoint>]
let main argv =
printfn "Hello, World!"
0
12 changes: 12 additions & 0 deletions hello-world/fsharp/code.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="code.fs" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions hello-world/go/code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
4 changes: 4 additions & 0 deletions hello-world/haskell/code.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, World!"
1 change: 1 addition & 0 deletions hello-world/js/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, World!");
7 changes: 7 additions & 0 deletions hello-world/jvm/code.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package jvm;

public class code {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
3 changes: 3 additions & 0 deletions hello-world/kotlin/code.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main() {
println("Hello, world!")
}
1 change: 1 addition & 0 deletions hello-world/lua/code.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, World!")
Loading

0 comments on commit b0b4742

Please sign in to comment.