checkpoint
diff --git a/src/tests/util/object.cpp b/src/tests/util/object.cpp index 32fd4b2..f3e4702 100644 --- a/src/tests/util/object.cpp +++ b/src/tests/util/object.cpp
@@ -5,9 +5,12 @@ Author: Leonardo de Moura */ #include <iostream> -#include "util/test.h" +// #include "util/test.h" +#include "runtime/debug.h" +#include "runtime/stackinfo.h" #include "util/object_ref.h" #include "util/init_module.h" +#include "util/timeit.h" using namespace lean; object * f(object *) { @@ -85,13 +88,126 @@ lean_assert(string_eq(r4, "hello world")); } +inline void array_set_obj1(object * o, size_t i, object * v) { + if (LEAN_LIKELY(!is_shared(o))) { + obj_set_data(o, sizeof(array_object) + sizeof(object*)*i, v); // NOLINT + } else { + } +} + +static void tst6(unsigned n, unsigned sz) { + timeit timer(std::cout, "tst6"); + object * a = alloc_array(sz, sz); + for (unsigned i = 0; i < n; i++) { + for (unsigned j = 0; j < sz; j++) { + array_set_obj1(a, j, box(j)); + } + } + dec_ref(a); +} + +static object * map1(object * l) { + if (obj_tag(l) == 0) { + return l; + } else { + object * h = cnstr_obj(l, 0); + object * t = cnstr_obj(l, 1); + object * new_h = box(unbox(h) + 1); + object * new_t = map1(t); + object * r = alloc_cnstr(1, 2, 0); + cnstr_set_obj(r, 0, new_h); + cnstr_set_obj(r, 1, new_t); + return r; + } +} + +static object * map2(object * l) { + if (obj_tag(l) == 0) { + return l; + } else { + object * h = cnstr_obj(l, 0); + object * t = cnstr_obj(l, 1); + inc(t); + dec(l); + object * new_h = box(unbox(h) + 1); + object * new_t = map2(t); + object * r = alloc_cnstr(1, 2, 0); + cnstr_set_obj(r, 0, new_h); + cnstr_set_obj(r, 1, new_t); + return r; + } +} + +static object * map3(object * l) { + if (obj_tag(l) == 0) { + return l; + } else { + object * h = cnstr_obj(l, 0); + object * t = cnstr_obj(l, 1); + bool s = is_shared(l); + if (s) { + inc(t); + dec(l); + } + object * new_h = box(unbox(h) + 1); + object * new_t = map3(t); + object * r; + if (s) { + std::cout << "FUCK\n"; + r = alloc_cnstr(1, 2, 0); + } else { + r = l; + } + cnstr_set_obj(r, 0, new_h); + cnstr_set_obj(r, 1, new_t); + return r; + } +} + +static object * mk_list(unsigned n) { + object * r = box(0); + while (n > 0) { + object * h = box(n); + object * new_r = alloc_cnstr(1, 2, 0); + cnstr_set_obj(new_r, 0, h); + cnstr_set_obj(new_r, 1, r); + r = new_r; + --n; + } + return r; +} + +static void tst7(unsigned n) { + timeit timer(std::cout, "tst7"); + object * l = mk_list(10000); + for (unsigned i = 0; i < n; i++) { + object * l2 = map3(l); + // dec(l); + l = l2; + } + dec(l); +} + +static void tst8(unsigned n) { + timeit timer(std::cout, "tst7"); + object * l = mk_list(100000); + for (unsigned i = 0; i < n; i++) { + object * l2 = map3(l); + l = l2; + } + dec(l); +} + + int main() { save_stack_info(); initialize_util_module(); - tst1(); - tst2(); - tst3(); - tst4(); + // tst1(); + // tst2(); + // tst3(); + // tst4(); + // tst6(1000000, 10000); + tst8(1000); finalize_util_module(); return has_violations() ? 1 : 0; }