diff --git a/CMakeLists.txt b/CMakeLists.txt index bc55a70..c5943af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -380,7 +380,8 @@ else() -fipa-pta -fext-dce -fstrict-enums - -fimplicit-constexpr) + -fimplicit-constexpr + -fomit-frame-pointer) add_compile_options(${OPTIONS_RELEASE}) add_link_options(-Wl,-O2 diff --git a/scripts_benchmark/Main.rb b/scripts_benchmark/Main.rb index 57200a2..12729bf 100644 --- a/scripts_benchmark/Main.rb +++ b/scripts_benchmark/Main.rb @@ -1,71 +1,113 @@ -# Engine benchmark idk, check speed via linux time utility -begin - RPG::Mod.exec_hooks("test", binding) - count = 0 - while count <= 500000 do - puts count - count += 1 - end - while count >= 1 do - puts count - count -= 1 - end - - count = 1.5 - while count <= 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 do - puts count - count = count * count +N = 5_000_000 +sink = 0 + +# 1. Цикл, арифметика и ветвления +i = 0 +while i < N + sink ^= (i * 31 + 17) % 1_000_003 + i += 1 +end + +# 2. Вызовы методов +class TestObject + def initialize(value) + @value = value end - count = 2 - while count <= 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 do - puts count - count = count * count + def calculate(x) + ((@value + x) * 3) ^ 0x55aa end - count = 1 - while count <= 5000 do - Graphics.frame_rate = count - count += 1 - end - - count = 1 - while count <= 60 do - Font.default_size = count - count += 1 - end - - Sunshine.crashprivacy=true - Wallpaper.reset - Input.set_led(255, 150, 30) - Graphics.freeze - Wallpaper.reset - File.exist?("oneshot") - Oneshot.exiting false - Oneshot.exiting true - puts CTime.month - puts CTime.day - puts CTime.hour - puts Sunshine::SDLVersion_major - puts Sunshine::SECURITYSTATE - puts Sunshine::DEVBUILD - count = 0 - while count <= 999999 do - count.clone - count = count + 1 - puts count - Graphics.update - begin - raise 'Boom!' - rescue - puts 'Rescued an exception.' - end - begin - 1 / 0 # Raises ZeroDivisionError, a subclass of StandardError. - rescue - puts "Rescued #{$!.class}" - end - end -rescue Errno::ENOENT - filename = $!.message.sub("No such file or directory - ", "") - print("Unable to find file #{filename}.") end + +objects = Array.new(10) { |x| TestObject.new(x) } + +i = 0 +while i < N + sink ^= objects[i % objects.length].calculate(i) + i += 1 +end + +# 3. Создание объектов и сборка мусора +i = 0 +while i < N + data = { + id: i, + name: "object_#{i}", + values: [i, i * 2, i * 3], + enabled: (i & 1) == 0 + } + + sink ^= data[:values][1] + i += 1 +end + +# 4. Строковые операции +text = "benchmark_string_" * 20 + +i = 0 +while i < N + value = "#{text}:#{i}".upcase.reverse + sink ^= value.length + i += 1 +end + +# 5. Массивы +array = Array.new(10_000) { |x| x } + +i = 0 +while i < N + array[i % array.length] = (array[i % array.length] * 31 + i) % 1_000_003 + sink ^= array[i % array.length] + i += 1 +end + +# 6. Hash lookup +hash = {} +10_000.times do |x| + hash["key_#{x}"] = x +end + +i = 0 +while i < N + sink ^= hash["key_#{i % 10_000}"] + i += 1 +end + +# 7. BigInt-арифметика +big = (1 << 100_000) + 12_345 + +200.times do + big = big * big + big %= (1 << 100_000) - 1 + sink ^= big & 0xffff +end + +# 8. Исключения +exception_count = 100_000 +i = 0 + +while i < exception_count + begin + raise RuntimeError, "benchmark error" + rescue RuntimeError + sink += 1 + end + + i += 1 +end + +# 9. clone / dup +object = { + name: "test", + values: Array.new(100, 123), + nested: { enabled: true } +} + +i = 0 +while i < N + copy = object.dup + sink ^= copy[:values].length + i += 1 +end + +puts "sink=#{sink}" diff --git a/src/debugwriter.h b/src/debugwriter.h index 1af794f..e84cfb9 100644 --- a/src/debugwriter.h +++ b/src/debugwriter.h @@ -26,7 +26,6 @@ #include #include #include -#include #include "meow.h" #undef vsnprintf #undef snprintf @@ -39,7 +38,7 @@ class Debug{ public: - explicit Debug(const std::source_location location = std::source_location::current()) : location(location){ + explicit Debug(){ buf << std::boolalpha; } @@ -65,22 +64,19 @@ public: return *this; } - ~Debug(){ - std::ostringstream result; - result << "[" << location.line() << ":" << location.function_name() << "] " << buf.view(); + ~Debug() noexcept { #ifdef __ANDROID__ __android_log_write(ANDROID_LOG_DEBUG, "sunshine", result.view().c_str()); #elif __EMSCRIPTEN__ emscripten_console_log(result.view().c_str()); #else - logs.emplace_back(result.view()); - std::cout << std::move(result).str() << '\n'; + logs.emplace_back(buf.view()); + std::cout << buf.view() << '\n'; #endif } private: std::ostringstream buf; - std::source_location location; }; #endif // DEBUGWRITER_H diff --git a/src/define.h b/src/define.h index a1e06f8..2c07d3b 100644 --- a/src/define.h +++ b/src/define.h @@ -1,5 +1,4 @@ #include - #if defined(SDL_PLATFORM_AIX) || defined(SDL_PLATFORM_BSDI) || defined(SDL_PLATFORM_FREEBSD) || \ defined(SDL_PLATFORM_HPUX) || defined(SDL_PLATFORM_HURD) || defined(SDL_PLATFORM_IRIX) || \ defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_NETBSD) || \ @@ -44,10 +43,6 @@ #define os2 1 #endif -#if SDL_PLATFORM_PS2 - #define ps2 1 -#endif - #if SDL_PLATFORM_PSP #define psp 1 #endif diff --git a/src/main.cpp b/src/main.cpp index 4a47001..30a13b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,6 @@ ** You should have received a copy of the GNU General Public License ** along with mkxp. If not, see . */ - #include #include #include @@ -337,10 +336,11 @@ int main(int argc, char *argv[]){ /* If RGSS thread ack'd request, wait for it to shutdown, * otherwise abandon hope and just end the process as is. */ - if (rtData.rqTermAck) + if (rtData.rqTermAck){ SDL_WaitThread(rgssThread, 0); - else + }else{ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and Sunshine will now force quit", win); + } if (!rtData.rgssErrorMsg.empty()) ErrorMsg(rtData.rgssErrorMsg.c_str());