https://www.purebasic.fr/blog/?p=486 PureBasic Team Blog random thoughts on PureBasic development Menu Skip to content * Home Sneak peek to C generated code Next major PureBasic version will feature a brand new C backend, which will allow to support virtually any CPU, current and future. The generated file is a big flat file, with no include directive to allow the fastest compilation speed as possible. In the meantime, we decided to create a C output as clean as possible to allow easy modification or even direct reuse into a C project. Let's take a look to it by comparing a PureBasic snippet and its generated C code counterpart: Procedure Test() Counter = Counter + 5 If Counter = 5 MessageRequester("Hello world", "Hello") EndIf ProcedureReturn 6 EndProcedure Test() And the generated C code (omitting all boilerplate) : static unsigned short _S1[]={72,101,108,108,111,32,119,111,114,108,100,0}; static unsigned short _S2[]={72,101,108,108,111,0}; static integer f_test() { integer r=0; integer v_counter=0; v_counter=(v_counter+5); if (v_counter==5) { integer rr0=PB_MessageRequester(_S1,_S2); } r=6; goto end; end: return r; } int __stdcall WinMain(void *instance, void *prevInstance, void *cmdLine, int cmdShow) { PB_Instance = GetModuleHandleW(0); PB_MemoryBase = HeapCreate(0,4096,0); SYS_InitString(); PB_InitDesktop(); PB_InitRequester(); integer rr1=f_test(); SYS_Quit(); } As we can see, the code is pretty close to PureBasic one, and easy to read. Inline C will be supported, and all the objects like variables, arrays, lists etc. could be accessed by following the generated token name pattern (example: 'v_' prefix for variables followed with the PureBasic name in lowercase). What about compilation speed ? We are using GCC 8.1.0 with no optimization (-O0) on Windows 10 x64 on a first gen Core i7 to perform the tests. We compile a 13.000 lines program, DocMaker, with debugger ON: * GCC backend: about 3 seconds to create the executable * FASM backend: about 1 second to create the executable So that's about 3 times slower but still an OK time to develop. Next test is a big program, the PureBasic IDE, with about 125.000 lines of codes with debugger ON. We also includes Microsoft VisualC++ 2015 in the tests: * GCC backend: about 24 seconds to create the executable * VC++ backend: about 9 seconds to create the executable * FASM backend: about 4 seconds to create the executable GCC is a lot slower, about 6 times, than the current FASM backend. The VC++ backend is about 2 times slower, which is much better but not that great. All in all, the FASM backend will still be better to use for quick development cycle. Keep in mind than it is very early tests and as we just seen, just switching the C compiler could dramatically increase compile time. That's it for now, next time we will focus about runtime performance between C and FASM backends ! This entry was posted in Compiler on April 22, 2021 by Fred. Post navigation - PureBasic and increased varieties of CPU Quick look to PureBasic C back-end performance - Search for: [ ] [Search] Categories * Coding * Compiler * Debugger * IDE * Libraries * Linux * Mac OSX * Releases * Tools * Uncategorized * Windows Archives * August 2021 * May 2021 * April 2021 * March 2021 * December 2018 * December 2017 * January 2016 * December 2015 * August 2014 * May 2014 * November 2013 * August 2013 * February 2013 * December 2012 * May 2012 * February 2012 * August 2011 * April 2011 * December 2010 * September 2010 * July 2010 * June 2010 * April 2010 * March 2010 * January 2010 * December 2009 * September 2009 * August 2009 * June 2009 * May 2009 * March 2009 * February 2009 * January 2009 * December 2008 * November 2008 * October 2008 * September 2008 * August 2008 Links * French forums * German forums * International forums * PureArea site * PureBasic site Meta * Log in * Entries feed * Comments feed * WordPress.org Proudly powered by WordPress