-
Notifications
You must be signed in to change notification settings - Fork 2
feat: bench for tutorials #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12bff76
feat: bench for tutorials
carsontung666 cbc2417
chore: restore kvspace-go v0.1.0
carsontung666 e480a11
chore: restore go.mod formatting
carsontung666 416366e
fix: keep benchmark PR focused
carsontung666 c442ea2
ci: remove benchmark smoke test
carsontung666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,22 @@ | ||
| #include <math.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main(void) { | ||
| volatile int lhs = 10; | ||
| volatile int rhs = 3; | ||
| volatile double base = 2.0; | ||
| volatile double exponent = 5.0; | ||
| volatile double radicand = 144.0; | ||
|
|
||
| printf("add: %d\n", lhs + rhs); | ||
| printf("sub: %d\n", lhs - rhs); | ||
| printf("mul: %d\n", lhs * rhs); | ||
| printf("mul(×): %d\n", lhs * rhs); | ||
| printf("div: %d\n", lhs / rhs); | ||
| printf("div(÷): %d\n", lhs / rhs); | ||
| printf("mod: %d\n", lhs % rhs); | ||
| printf("pow: %.1f\n", pow(base, exponent)); | ||
| printf("sqrt: %.1f\n", sqrt(radicand)); | ||
| printf("sqrt(√): %.1f\n", sqrt(radicand)); | ||
| return 0; | ||
| } |
This file contains hidden or 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 @@ | ||
| import math | ||
|
|
||
|
|
||
| lhs = 10 | ||
| rhs = 3 | ||
| base = 2.0 | ||
| exponent = 5.0 | ||
| radicand = 144.0 | ||
|
|
||
| print("add:", lhs + rhs) | ||
| print("sub:", lhs - rhs) | ||
| print("mul:", lhs * rhs) | ||
| print("mul(×):", lhs * rhs) | ||
| print("div:", lhs // rhs) | ||
| print("div(÷):", lhs // rhs) | ||
| print("mod:", lhs % rhs) | ||
| print("pow:", base**exponent) | ||
| print("sqrt:", math.sqrt(radicand)) | ||
| print("sqrt(√):", math.sqrt(radicand)) |
This file contains hidden or 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,6 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int main(void) { | ||
| puts("hello kvlang"); | ||
| return 0; | ||
| } |
This file contains hidden or 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 @@ | ||
| print("hello kvlang") |
This file contains hidden or 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,15 @@ | ||
| #include <stdio.h> | ||
|
|
||
| static long long factorial(int n) { | ||
| long long result = 1; | ||
| for (int i = 1; i <= n; ++i) { | ||
| result *= i; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| int main(void) { | ||
| volatile int n = 10; | ||
| printf("fact = %lld\n", factorial(n)); | ||
| return 0; | ||
| } |
This file contains hidden or 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 hidden or 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,8 @@ | ||
| def factorial(n: int) -> int: | ||
| result = 1 | ||
| for i in range(1, n + 1): | ||
| result *= i | ||
| return result | ||
|
|
||
|
|
||
| print("fact =", factorial(10)) |
This file contains hidden or 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,21 @@ | ||
| #include <stdio.h> | ||
|
|
||
| static long long fibonacci(int n) { | ||
| if (n <= 1) { | ||
| return n; | ||
| } | ||
| long long a = 0; | ||
| long long b = 1; | ||
| for (int i = 2; i <= n; ++i) { | ||
| long long next = a + b; | ||
| a = b; | ||
| b = next; | ||
| } | ||
| return b; | ||
| } | ||
|
|
||
| int main(void) { | ||
| volatile int n = 10; | ||
| printf("fib = %lld\n", fibonacci(n)); | ||
| return 0; | ||
| } |
This file contains hidden or 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 hidden or 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,10 @@ | ||
| def fibonacci(n: int) -> int: | ||
| if n <= 1: | ||
| return n | ||
| a, b = 0, 1 | ||
| for _ in range(2, n + 1): | ||
| a, b = b, a + b | ||
| return b | ||
|
|
||
|
|
||
| print("fib =", fibonacci(10)) |
This file contains hidden or 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,15 @@ | ||
| #include <stdio.h> | ||
|
|
||
| static long long gcd(long long a, long long b) { | ||
| if (b == 0) { | ||
| return a; | ||
| } | ||
| return gcd(b, a % b); | ||
| } | ||
|
|
||
| int main(void) { | ||
| volatile long long a = 48; | ||
| volatile long long b = 18; | ||
| printf("gcd = %lld\n", gcd(a, b)); | ||
| return 0; | ||
| } |
This file contains hidden or 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 hidden or 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,7 @@ | ||
| def gcd(a: int, b: int) -> int: | ||
| if b == 0: | ||
| return a | ||
| return gcd(b, a % b) | ||
|
|
||
|
|
||
| print("gcd =", gcd(48, 18)) |
This file contains hidden or 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,27 @@ | ||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
|
|
||
| static void prime_sieve(int limit) { | ||
| printf("primes up to %d\n", limit); | ||
| int count = 0; | ||
| for (int n = 2; n <= limit; ++n) { | ||
| bool is_prime = true; | ||
| for (int divisor = 2; divisor < n; ++divisor) { | ||
| if (n % divisor == 0) { | ||
| is_prime = false; | ||
| break; | ||
| } | ||
| } | ||
| if (is_prime) { | ||
| printf(" prime: %d\n", n); | ||
| ++count; | ||
| } | ||
| } | ||
| printf("total primes up to %d = %d\n", limit, count); | ||
| } | ||
|
|
||
| int main(void) { | ||
| volatile int limit = 30; | ||
| prime_sieve(limit); | ||
| return 0; | ||
| } |
This file contains hidden or 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 hidden or 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,16 @@ | ||
| def prime_sieve(limit: int) -> None: | ||
| print("primes up to", limit) | ||
| count = 0 | ||
| for n in range(2, limit + 1): | ||
| is_prime = True | ||
| for divisor in range(2, n): | ||
| if n % divisor == 0: | ||
| is_prime = False | ||
| break | ||
| if is_prime: | ||
| print(" prime:", n) | ||
| count += 1 | ||
| print("total primes up to", limit, "=", count) | ||
|
|
||
|
|
||
| prime_sieve(30) |
This file contains hidden or 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,7 @@ | ||
| file,kvlang_ms,python_ms,c_ms | ||
| tutorial/01-basics/arith.kv,376.663,25.367,5.123 | ||
| tutorial/01-basics/hello.kv,86.866,24.346,4.780 | ||
| tutorial/04-algo/factorial.kv,917.746,25.138,5.087 | ||
| tutorial/04-algo/fibonacci.kv,1225.605,25.423,5.636 | ||
| tutorial/04-algo/gcd.kv,729.042,24.436,4.597 | ||
| tutorial/04-algo/prime_sieve.kv,22567.890,25.147,5.014 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.