Skip to content
EnjoyW0rld edited this page Apr 23, 2023 · 4 revisions

Godot C# and C++ comparison

Brief description:

Godot is a free and open-source game engine that is used by game developers to create 2D and 3D games for various platforms, including desktop, mobile, and web. Godot supports multip le programming languages-

  • C#
  • GDScript
  • Visual scripting (not anymore used in the newest verison)

Engine itself is written using C++ and allows user to add modules or change existing ones. To create this prototype I red official documentation of Godot 3.5, and explicitly documentation on C# in Godot to learn how to connect and use it. To learn how to build and work with an engine itself I watched this video to find out how to build Godot with C# module and this playlist to understand how to implement and connect your own C++ modules

Evaluation proposal: Implement the same task solution on C++ and C# in Godot game engine to compare it efficiency in time it took and memory it used to complete the task. As a testing task I will implement N-Queen solver.

N-Queen problem: The N-Queens problem is a classic puzzle and mathematical problem in which a set of N chess queens have to be placed on an N x N chessboard, such that no two queens threaten each other.

Relevance: Godot game engine is free and open-source, which makes it accessible and affordable for indie developers and game studious (Salmela.T.(2022)). It is being constantly updated and improved since 2014 till current moment(2023) not only by developers, but also by the community who are adding modules, documentation and tutorials (Flomén, R.,Gustafsson, M.(2020)).

  • Salmela, T. (2022). Game development using the open-source Godot Game Engine.
  • Flomén, R., & Gustafsson, M. (2020). Game developer experience: A cognitive task analysis with different game engines.

N-Queen implementation

For the task I implemented N-Queen problem that finds all possible solutions using recursive method. The complexity of function is O(n!). Implementation in both languages is the same with only changed to variable types specific to the language.

Comparing С++/C# speed

For this test I compared time it takes to solve N-Queen problem with different amount of queens on both C# and C++ languages. I ended solving at size of 15 because after that amount of queens it takes way too much time for any possible game to do during runtime. Graph starts from 6 queens because for both languages solving queens from 1 to 5 takes one or less milliseconds.

image

Average time scaling factor for C++ is 5.34 and for C# is 5.77 (this means that every next queen count will take approximately 5.34 or 5.77 more time then previous).

Analysis

The chart shows that on average it takes less time for C# to perform this task. In real game it is possible to use both languages for this task up to scale of 9 for player not to notice time it took to compute it. For the situation where it is necessary to compute some complicated task, it would be more profitable to use C# as it takes ~45.71% less time to compute.

Comparing C++/C# memory usage

For this test I measured memory consumption starting from 1 queen up to 15. This time I started from one because application needs some memory by default so there is data to collect. I stopped at 15 by the same reason as during previous test - because of the amount of time it takes to compute it can not be used in any game.

image

Average memory scaling factor for C++ is 1.689 and for C# is 1.459

Analysis

In a range from 1 to 13 queens, C++ take less memory to compute than C#, but starting from 14 it is the other way around. Looking at the trending line and taking in account scaling factor provided before we clearly see that it is more profitable to use C++ in a cases where we need to do smaller computation. It takes around ~34% less memory to perform this task for C++ which is pretty big difference for a small project.

Summary

Both languages could be successfully used to perform this task, but the are cases when it is more profitable to chose one and not the other.

  • For the case when you need to perform smaller computation, C++ did the task for around the same time and at the same moment took ~34% less memory.
  • For the case when you need to perform bigger and more complex computation, C# showed itself better being ~45.71% faster at big complexity than C++ and at the same time taking less memory