-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_example.ecl
More file actions
56 lines (48 loc) · 1020 Bytes
/
bench_example.ecl
File metadata and controls
56 lines (48 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
// Example benchmark file demonstrating the benchmarking framework
def fibonacci(n: Int) -> Int {
if n <= 1 {
n
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}
def factorial(n: Int) -> Int {
if n <= 1 {
1
} else {
n * factorial(n - 1)
}
}
def sum_range(n: Int) -> Int {
if n <= 0 {
0
} else {
n + sum_range(n - 1)
}
}
#[bench]
def bench_fibonacci_10() -> Int {
fibonacci(10)
}
#[bench]
def bench_factorial_10() -> Int {
factorial(10)
}
#[bench]
def bench_sum_100() -> Int {
sum_range(100)
}
#[bench]
#[ignore]
def bench_slow_operation() -> Int {
// This benchmark is ignored as it's too slow
fibonacci(20)
}
fn main() {
println("=== Benchmark Demo (manual run) ===")
println("fibonacci(10) =", fibonacci(10))
println("factorial(10) =", factorial(10))
println("sum_range(100) =", sum_range(100))
println("Use `eclexia bench` to run #[bench] functions.")
}