This commit is contained in:
pikastech 2022-10-09 00:24:33 +08:00
parent c660f400ac
commit 72aa1f8f95
3 changed files with 49 additions and 7 deletions

View File

@ -2051,3 +2051,37 @@ TEST(vm, benchmark) {
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, for_print_1k) {
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
/* clang-format off */
PIKA_PYTHON(
for i in range(1000):
print(i)
)
/* clang-format on */
const uint8_t bytes[] = {
0x30, 0x00, /* instruct array size */
0x20, 0x85, 0x01, 0x00, 0x10, 0x02, 0x06, 0x00, 0x00, 0x02, 0x0c, 0x00,
0x00, 0x04, 0x11, 0x00, 0x00, 0x82, 0x15, 0x00, 0x00, 0x04, 0x22, 0x00,
0x00, 0x0d, 0x22, 0x00, 0x00, 0x07, 0x24, 0x00, 0x11, 0x81, 0x22, 0x00,
0x01, 0x02, 0x26, 0x00, 0x00, 0x86, 0x2c, 0x00, 0x00, 0x8c, 0x11, 0x00,
/* instruct array */
0x2f, 0x00, /* const pool size */
0x00, 0x31, 0x30, 0x30, 0x30, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00,
0x69, 0x74, 0x65, 0x72, 0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30,
0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00,
0x32, 0x00, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x00, 0x2d, 0x31,
0x00, /* const pool */
};
pikaVM_runByteCode(pikaMain, (uint8_t*)bytes);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -677,3 +677,11 @@ TEST(compiler, benchmark) {
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, for_print_1k) {
char* lines =
"for i in range(1000):\n"
" print(i)\n";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -11,12 +11,12 @@ int main(int argc, char** argv) {
int res = RUN_ALL_TESTS();
mem_pool_deinit();
extern PikaMemInfo pikaMemInfo;
if (PIKA_ASSERT_ENABLE) {
printf("[ Info]: alloc times: %d, cached times: %d (%0.2f%%)\r\n",
pikaMemInfo.alloc_times, pikaMemInfo.alloc_times_cache,
((float)pikaMemInfo.alloc_times_cache /
(float)pikaMemInfo.alloc_times) *
100.0);
}
#if PIKA_ARG_CACHE_ENABLE
printf("[ Info]: alloc times: %d, cached times: %d (%0.2f%%)\r\n",
pikaMemInfo.alloc_times, pikaMemInfo.alloc_times_cache,
((float)pikaMemInfo.alloc_times_cache /
(float)pikaMemInfo.alloc_times) *
100.0);
#endif
return res;
}