More compile timers, euler3
This commit is contained in:
@@ -484,6 +484,7 @@ gen_ast(Ast *ast){
|
||||
|
||||
function String
|
||||
compile_string(String filecontent, String filename = "default_name"_s){
|
||||
F64 total_time = os_time();
|
||||
Scratch scratch(thread_ctx.scratch);
|
||||
OS_Heap heap = win32_os_heap_create(false, mib(4), 0);
|
||||
|
||||
@@ -559,6 +560,7 @@ int main(){
|
||||
printf("\n// Resolving : %f", resolve_end - resolve_begin);
|
||||
printf("\n// Codegen : %f", codegen_end - codegen_begin);
|
||||
printf("\n// Flattening : %f", flattening_end - flattening_begin);
|
||||
printf("\n// Total : %f", flattening_end - total_time);
|
||||
printf("\n//-------------------------------");
|
||||
|
||||
return string_result;
|
||||
|
||||
17
euler.kl
17
euler.kl
@@ -6,10 +6,11 @@ entry :: ()
|
||||
euler3()
|
||||
|
||||
// @todo: Add more stats in the preview
|
||||
// @todo: for 0..1000(implicit i) and for i in 0..1000
|
||||
// @todo: Add blocks of stmts that you can simply define inside a function etc.
|
||||
euler1 :: ()
|
||||
end := 1000
|
||||
result := 0
|
||||
// @todo: for 0..1000(implicit i) and for i in 0..1000
|
||||
for i := 0, i < end, i++
|
||||
if i % 3 == 0
|
||||
result += i
|
||||
@@ -27,16 +28,16 @@ int_sqrt1 :: (s: S64): S64
|
||||
x0 := s / 2
|
||||
|
||||
if x0 != 0
|
||||
x1 := ( x0 + s / x0 ) / 2
|
||||
x1 := (x0 + s / x0) / 2
|
||||
for x1 < x0
|
||||
x0 = x1
|
||||
x1 = ( x0 + s / x0 ) / 2
|
||||
x1 = (x0 + s / x0) / 2
|
||||
return x0
|
||||
else
|
||||
return s
|
||||
|
||||
euler3 :: ()
|
||||
n := 13195
|
||||
n := 600851475143
|
||||
results: [32]S64
|
||||
results_len := 0
|
||||
|
||||
@@ -45,13 +46,15 @@ euler3 :: ()
|
||||
results[results_len++] = 2
|
||||
n /= 2
|
||||
|
||||
print_int(int_sqrt(n))
|
||||
// Then search other primes, 3, 5, 7 etc.
|
||||
for i := 3, i <= int_sqrt(n), i += 2
|
||||
for i := 3, i <= int_sqrt1(n), i += 2
|
||||
for n % i == 0
|
||||
results[results_len++] = i
|
||||
n /= i
|
||||
|
||||
if n > 2
|
||||
results[results_len++] = n
|
||||
|
||||
printf("Euler3: ")
|
||||
|
||||
is_correct: S64 = 1
|
||||
@@ -63,8 +66,6 @@ euler3 :: ()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print_int :: (i: S64)
|
||||
printf("%lld ", i)
|
||||
|
||||
|
||||
9
main.cpp
9
main.cpp
@@ -187,14 +187,19 @@ int main(int argument_count, char **arguments){
|
||||
Scratch scratch;
|
||||
String name = string_fmt(scratch, "%s.kl", arguments[1]);
|
||||
String c_filename = string_fmt(scratch, "%s.c", arguments[1]);
|
||||
String call = string_fmt(scratch, "clang.exe %s.c -g -o %s.exe && %s.exe", arguments[1], arguments[1], arguments[1]);
|
||||
String compiler_call = string_fmt(scratch, "clang.exe %s.c -g -o %s.exe", arguments[1], arguments[1]);
|
||||
String run_program = string_fmt(scratch, "%s.exe", arguments[1]);
|
||||
|
||||
String result = compile_file(name);
|
||||
FILE *f = fopen((const char *)c_filename.str, "w");
|
||||
assert(f);
|
||||
fprintf(f, "%.*s", (int)result.len, result.str);
|
||||
fclose(f);
|
||||
system((const char *)call.str);
|
||||
F64 begin = os_time();
|
||||
system((const char *)compiler_call.str);
|
||||
printf("\nCompile time: %f", os_time() - begin);
|
||||
|
||||
system((const char *)run_program.str);
|
||||
}
|
||||
else{
|
||||
String result = {};
|
||||
|
||||
Reference in New Issue
Block a user