forked from bddicken/languages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package name as `java` is not allow, hence the folder is called `jvm`.
- Loading branch information
1 parent
fd34795
commit f71f8c2
Showing
7 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.class | ||
code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
rm c/code | ||
rm go/code | ||
rm jvm/code.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
clang -O3 c/code.c -o c/code | ||
go build -o go/code go/code.go | ||
javac jvm/code.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jvm; | ||
|
||
public class code { | ||
|
||
private static int fibonacci(int n) { | ||
if (n == 0) { | ||
return 0; | ||
} | ||
if (n == 1) { | ||
return 1; | ||
} | ||
return fibonacci(n - 1) + fibonacci(n - 2); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var u = Integer.parseInt(args[0]); | ||
var r = 0; | ||
for (var i = 1; i < u; i++) { | ||
r += fibonacci(i); | ||
} | ||
System.out.println(r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package jvm; | ||
|
||
import java.util.Random; | ||
|
||
public class code { | ||
|
||
public static void main(String[] args) { | ||
var u = Integer.parseInt(args[0]); // Get an input number from the command line | ||
var r = new Random().nextInt(10000); // Get a random number 0 <= r < 10k | ||
var a = new int[10000]; // Array of 10k elements initialized to 0 | ||
for (var i = 0; i < 10000; i++) { // 10k outer loop iterations | ||
for (var j = 0; j < 100000; j++) { // 100k inner loop iterations, per outer loop iteration | ||
a[i] = a[i] + j % u; // Simple sum | ||
} | ||
a[i] += r; // Add a random value to each element in array | ||
} | ||
System.out.println(a[r]); // Print out a single element from the array | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters