Try not to optimize the loop
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
64f41ad5b9
commit
aa1e940362
2 changed files with 9 additions and 4 deletions
13
testdata/addupto.zig
vendored
13
testdata/addupto.zig
vendored
|
|
@ -1,9 +1,14 @@
|
|||
const expect = @import("std").testing.expect;
|
||||
|
||||
pub export fn addUpTo(to: u32) u32 {
|
||||
var res: u32 = 0;
|
||||
for (0..to) |_| {
|
||||
res += to;
|
||||
pub export fn addUpTo(to: i32) i32 {
|
||||
var res: i32 = 0;
|
||||
for (0..@intCast(to)) |i| {
|
||||
const ii: i32 = @intCast(i);
|
||||
if (ii < 20) {
|
||||
res += ii * to;
|
||||
} else {
|
||||
res += ii + to * 2;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
BIN
testdata/zig-out/bin/addUpTo.wasm
vendored
BIN
testdata/zig-out/bin/addUpTo.wasm
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue