Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded fibonacci to deal with large numbers #1019

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions benchmarks/fibonacci/go/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"fmt"
"net"
"strconv"
"math/big"

pb "github.com/vhive-serverless/vSwarm-proto/proto/fibonacci"
tracing "github.com/vhive-serverless/vSwarm/utils/tracing/go"
Expand All @@ -42,14 +43,19 @@ var (
address = flag.String("addr", "0.0.0.0:50051", "Address:Port the grpc server is listening to")
)

func fibonacci(num int) float64 {
var num1 float64 = 0
var num2 float64 = 1
var sum float64
func fibonacci(num int) *big.Int {
if num <= 0 {
return big.NewInt(0)
}

num1 := big.NewInt(0)
num2 := big.NewInt(1)
sum := big.NewInt(0)

for i := 0; i < num; i++ {
sum = num1 + num2
num1 = num2
num2 = sum
sum.Add(num1, num2)
num1.Set(num2)
num2.Set(sum)
}
return num1
}
Expand All @@ -64,7 +70,7 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
// log.Printf("Received: %v", in.GetName())
x, _ := strconv.ParseInt(in.GetName(), 10, 64)
var y = fibonacci(int(x))
resp := fmt.Sprintf("fn: Fib: y = fib(x) | x: %d y: %.1f | runtime: GoLang", x, y)
resp := fmt.Sprintf("fn: Fib: y = fib(x) | x: %d y: %s | runtime: GoLang", x, y.String())
return &pb.HelloReply{Message: resp}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions benchmarks/fibonacci/nodejs/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ var hello_proto = grpc.loadPackageDefinition(packageDefinition).fibonacci;


function fibonacci(num) {
var num1 = 0;
var num2 = 1;
var sum;
let num1 = BigInt(0);
let num2 = BigInt(1);
let sum = BigInt(0);
var i = 0;
for (i = 0; i < num; i++) {
sum = num1 + num2;
num1 = num2;
num2 = sum;
}
return num1;
return num1.toString();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/fibonacci/python/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
tracing.grpcInstrumentClient()
tracing.grpcInstrumentServer()

sys.set_int_max_str_digits(500000)

def fibonacci(num):
num1=0
num2=1
Expand All @@ -79,7 +81,7 @@ def SayHello(self, request, context):
y = fibonacci(x)

gid = syscall(104)
msg = "fn: Fib: y = fib(x) | x: %i y: %.1f | runtime: python" % (x,y)
msg = "fn: Fib: y = fib(x) | x: %i y: %i | runtime: python" % (x,y)
return fibonacci_pb2.HelloReply(message=msg)


Expand Down
Loading