Skip to content

xorz57/Tracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tracer

Dependencies

Examples

Factorial 1

#include <iostream>

#include "Tracer.hpp"

std::uint64_t factorial(std::uint64_t n) {
	TRACER_SCOPE("factorial", "function", { {"n", n} });
	if (n <= 1) return 1;
	return n * factorial(n - 1);
}

int main() {
	std::cout << factorial(10) << std::endl;
	TRACER_DUMP("trace.json", 4);
}

Factorial1

Fibonacci 1

#include <iostream>

#include "Tracer.hpp"

std::uint64_t fibonacci(std::uint64_t n) {
	TRACER_SCOPE("fibonacci", "function", { {"n", n} });
	if (n <= 1) return n;
	return fibonacci(n - 1) + fibonacci(n - 2);
}

int main() {
	std::cout << fibonacci(10) << std::endl;
	TRACER_DUMP("trace.json", 4);
}

Fibonacci1

Factorial 2

#include <iostream>

#include "Tracer.hpp"

std::uint64_t factorial(std::uint64_t n) {
	TRACER_SCOPE("factorial", "function", { {"n", n} });
	std::uint64_t result = 1;
	for (std::uint64_t i = 2; i <= n; ++i) {
		result *= i;
	}
	return result;
}

int main() {
	std::cout << factorial(10) << std::endl;
	TRACER_DUMP("trace.json", 4);
}

Factorial2

Fibonacci 2

#include <iostream>

#include "Tracer.hpp"

std::uint64_t fibonacci(std::uint64_t n) {
	TRACER_SCOPE("fibonacci", "function", { {"n", n} });
	if (n <= 1) return n;
	std::uint64_t a = 0;
	std::uint64_t b = 1;
	for (std::uint64_t i = 2; i <= n; ++i) {
		std::uint64_t c = a + b;
		a = b;
		b = c;
	}
	return b;
}

int main() {
	std::cout << fibonacci(10) << std::endl;
	TRACER_DUMP("trace.json", 4);
}

Fibonacci2