GithubHelp home page GithubHelp logo

drujensen / riscv-fibonacci Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 3.0 14 KB

Recursive Fibonacci Benchmark running on RISC-V

License: MIT License

Java 2.72% C 2.47% C++ 2.24% Go 1.92% JavaScript 1.42% PHP 1.40% Raku 1.42% Python 1.05% Ruby 73.04% Rust 1.75% Assembly 6.99% Swift 1.40% Zig 2.19%

riscv-fibonacci's Introduction

Recursive Fibonacci Benchmark running on RISC-V

Languages: Assembly, C, C++, Go, Rust, Java, NodeJS, Ruby, Python3, Perl

The code performs a recursive fibonacci to the 42th position with the result of 267,914,296.

Fibonacci can be written many different ways. The goal of this project is to compare how each language handles the exact same code.

Here is the Ruby version:

def fib(n)
  return n if n <= 1
  fib(n - 1) + fib(n - 2)
end

puts fib(42)

Here is the Python version:

def fib(n):
  if n <= 1: return n
  return fib(n - 1) + fib(n - 2)

print(fib(42))

Too keep a level playing field, only common "release" flags are used in the compilation step. This allows for compiler optimizations like inlining and constant propogation but removes anything considered dangerous i.e. bypassing out of bounds checks.

All tests are run on:

  • Mac M1 Pro 32GB (Host)
  • Docker Desktop 4.16.2
  • Docker Ubuntu 22.04 RISC-V 64bit Image

How to run them

You can run the tests using Docker:

docker run --platform linux/riscv64 -it drujensen/riscv-ubuntu bash

Then clone the repo and run the tests:

git clone https://github.com/drujensen/riscv-fibonacci.git
cd riscv-fibonacci
./run.sh

Results

Last benchmark was ran on February 12, 2023

Natively compiled, statically typed

Language Total Compile Time, s Run Time, s Ext
C 2.228 gcc -O3 -o fib fib.c 0.821 ./fib 1.407 c
C++ 2.343 g++ -O3 -o fib fib.cpp 0.927 ./fib 1.416 cpp
Assembly 7.202 gcc -O3 -o fib fib.s 0.244 ./fib 6.958 s
Go 8.689 go build fib.go 0.889 ./fib 7.800 go
Rust 10.766 rustc -C opt-level=3 fib.rs 3.454 ./fib 7.312 rs

VM compiled bytecode, statically typed

Language Total Compile Time, s Run Time, s Ext
Java 9.231 javac Fib.java 3.740 java Fib 5.491 java

VM compiled before execution, mixed/dynamically typed

Language Time, s Run Ext
Ruby (jit) 42.278 ruby --jit fib.rb rbjit
Node 208.353 node fib.js js

Interpreted, dynamically typed

Language Time, s Run Ext
Ruby 197.762 ruby fib.rb rb
Python3 651.567 python3 fib.py py
Perl 762.013 perl fib.pl pl

Contributing

If you would like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

To add other languages, please add them to the Dockerfile found here:

https://github.com/drujensen/riscv-ubuntu/blob/main/Dockerfile

License

The code is available as open source under the terms of the MIT License.

riscv-fibonacci's People

Contributors

drujensen avatar trepetti avatar

Stargazers

 avatar  avatar Spreequalle avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.