Auto benchmarking with moon

Asked

Viewed 96 times

1

A script in C or C++ could write algorithms in Lua (by Brut force, that is, test several possible combinations) based on a database with the results of the algorithms.

The idea is to get to the most efficient algorithm for a certain goal, for example, I developed an algorithm for calculating statistics, I want to get to a more efficient, without losing focus.

Is there any library or way to test the speed of a code in Lua or C/C++ using C++?

  • I’m not sure this brute-force strategy is such a good idea. First, in the general case it is impossible to write an algorithm to decide whether a given program obeys a given specification - its tests with the data bank will allow false positives. Also, your search space grows exponentially with the length of the program which means that you will need a lot of luck to be able to find some non-trivial solution.

1 answer

4

It’s not as clear as you’re generating the algorithms on the moon, but there are two simple ways to make the code run. The first is to lynch your program with the moon interpreter as a library. Then you can execute code that is in a string loading it with luaL_loadstring and then invoking lua_pcall. The other way would be to save the script to a file and then use system("lua myscript.lua"), as the interpreter is installed on your system.

Having this you can make a very simple benchmark, but not as accurate, using the function clock() of C. Or classes chrono of C++. The idea is to measure the time before and after the execution and calculate the difference. It is important to make multiple measurements to ensure a good result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.