Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "benchmark.h"
- #include <cstddef>
- #include <godot_cpp/core/class_db.hpp>
- #include <godot_cpp/classes/engine.hpp>
- #include <godot_cpp/variant/utility_functions.hpp>
- using namespace godot;
- void Benchmark::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_limit"), &Benchmark::get_limit);
- ClassDB::bind_method(D_METHOD("set_limit", "p_limit"), &Benchmark::set_limit);
- ClassDB::bind_method(D_METHOD("how_many_primes" , "p_limit"), &Benchmark::how_many_primes);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "limit"), "set_limit", "get_limit");
- }
- Benchmark::Benchmark() {
- // Initialize any variables here.
- limit = 25000;
- }
- Benchmark::~Benchmark() {
- // Add your cleanup here.
- }
- void Benchmark::_ready() {
- if(Engine::get_singleton()->is_editor_hint()) { return; }
- // how_many_primes(limit);
- }
- int Benchmark::is_prime(int n) {
- for (int i = 2 ; i <= n/2 ; ++i) {
- if (n % i == 0) { return 0;}
- }
- return 1;
- }
- int Benchmark::how_many_primes(int p_limit) {
- int numPrimes = 0;
- for (int i = 2; i < p_limit; ++i) {
- numPrimes += is_prime(i) ;
- }
- UtilityFunctions::print(numPrimes);
- return numPrimes;
- }
- void Benchmark::set_limit(const int p_limit) {
- limit = p_limit;
- }
- int Benchmark::get_limit() const {
- return limit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement