mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Separate the into multiple files similar to the vogl zip64 version of the library.
If anyone wants to have a minified version of if a script could be written to do this automatically.
This commit is contained in:
		
							
								
								
									
										1809
									
								
								tests/miniz_tester.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1809
									
								
								tests/miniz_tester.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										152
									
								
								tests/timer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								tests/timer.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,152 @@ | ||||
| // File: timer.cpp - Simple high-precision timer class. Supports Win32, X360, and POSIX/Linux | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include <assert.h> | ||||
| #include <time.h> | ||||
|  | ||||
| #include "timer.h" | ||||
|  | ||||
| #if defined(WIN32) | ||||
| #include <windows.h> | ||||
| #elif defined(_XBOX) | ||||
| #include <xtl.h> | ||||
| #endif | ||||
|  | ||||
| unsigned long long timer::g_init_ticks; | ||||
| unsigned long long timer::g_freq; | ||||
| double timer::g_inv_freq; | ||||
|  | ||||
| #if defined(WIN32) || defined(_XBOX) | ||||
| inline void query_counter(timer_ticks *pTicks) | ||||
| { | ||||
|    QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks)); | ||||
| } | ||||
| inline void query_counter_frequency(timer_ticks *pTicks) | ||||
| { | ||||
|    QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks)); | ||||
| } | ||||
| #elif defined(__GNUC__) | ||||
| #include <sys/timex.h> | ||||
| inline void query_counter(timer_ticks *pTicks) | ||||
| { | ||||
|    struct timeval cur_time; | ||||
|    gettimeofday(&cur_time, NULL); | ||||
|    *pTicks = static_cast<unsigned long long>(cur_time.tv_sec)*1000000ULL + static_cast<unsigned long long>(cur_time.tv_usec); | ||||
| } | ||||
| inline void query_counter_frequency(timer_ticks *pTicks) | ||||
| { | ||||
|    *pTicks = 1000000; | ||||
| } | ||||
| #endif | ||||
|  | ||||
| timer::timer() : | ||||
|    m_start_time(0), | ||||
|    m_stop_time(0), | ||||
|    m_started(false), | ||||
|    m_stopped(false) | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|       init(); | ||||
| } | ||||
|  | ||||
| timer::timer(timer_ticks start_ticks) | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|       init(); | ||||
|  | ||||
|    m_start_time = start_ticks; | ||||
|  | ||||
|    m_started = true; | ||||
|    m_stopped = false; | ||||
| } | ||||
|  | ||||
| void timer::start(timer_ticks start_ticks) | ||||
| { | ||||
|    m_start_time = start_ticks; | ||||
|  | ||||
|    m_started = true; | ||||
|    m_stopped = false; | ||||
| } | ||||
|  | ||||
| void timer::start() | ||||
| { | ||||
|    query_counter(&m_start_time); | ||||
|  | ||||
|    m_started = true; | ||||
|    m_stopped = false; | ||||
| } | ||||
|  | ||||
| void timer::stop() | ||||
| { | ||||
|    assert(m_started); | ||||
|  | ||||
|    query_counter(&m_stop_time); | ||||
|  | ||||
|    m_stopped = true; | ||||
| } | ||||
|  | ||||
| double timer::get_elapsed_secs() const | ||||
| { | ||||
|    assert(m_started); | ||||
|    if (!m_started) | ||||
|       return 0; | ||||
|  | ||||
|    timer_ticks stop_time = m_stop_time; | ||||
|    if (!m_stopped) | ||||
|       query_counter(&stop_time); | ||||
|  | ||||
|    timer_ticks delta = stop_time - m_start_time; | ||||
|    return delta * g_inv_freq; | ||||
| } | ||||
|  | ||||
| timer_ticks timer::get_elapsed_us() const | ||||
| { | ||||
|    assert(m_started); | ||||
|    if (!m_started) | ||||
|       return 0; | ||||
|  | ||||
|    timer_ticks stop_time = m_stop_time; | ||||
|    if (!m_stopped) | ||||
|       query_counter(&stop_time); | ||||
|  | ||||
|    timer_ticks delta = stop_time - m_start_time; | ||||
|    return (delta * 1000000ULL + (g_freq >> 1U)) / g_freq; | ||||
| } | ||||
|  | ||||
| void timer::init() | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|    { | ||||
|       query_counter_frequency(&g_freq); | ||||
|       g_inv_freq = 1.0f / g_freq; | ||||
|  | ||||
|       query_counter(&g_init_ticks); | ||||
|    } | ||||
| } | ||||
|  | ||||
| timer_ticks timer::get_init_ticks() | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|       init(); | ||||
|  | ||||
|    return g_init_ticks; | ||||
| } | ||||
|  | ||||
| timer_ticks timer::get_ticks() | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|       init(); | ||||
|  | ||||
|    timer_ticks ticks; | ||||
|    query_counter(&ticks); | ||||
|    return ticks - g_init_ticks; | ||||
| } | ||||
|  | ||||
| double timer::ticks_to_secs(timer_ticks ticks) | ||||
| { | ||||
|    if (!g_inv_freq) | ||||
|       init(); | ||||
|  | ||||
|    return ticks * g_inv_freq; | ||||
| } | ||||
|  | ||||
							
								
								
									
										40
									
								
								tests/timer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/timer.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| // File: timer.h | ||||
| #pragma once | ||||
|  | ||||
| typedef unsigned long long timer_ticks; | ||||
|  | ||||
| class timer | ||||
| { | ||||
| public: | ||||
|    timer(); | ||||
|    timer(timer_ticks start_ticks); | ||||
|  | ||||
|    void start(); | ||||
|    void start(timer_ticks start_ticks); | ||||
|  | ||||
|    void stop(); | ||||
|  | ||||
|    double get_elapsed_secs() const; | ||||
|    inline double get_elapsed_ms() const { return get_elapsed_secs() * 1000.0f; } | ||||
|    timer_ticks get_elapsed_us() const; | ||||
|  | ||||
|    static void init(); | ||||
|    static inline timer_ticks get_ticks_per_sec() { return g_freq; } | ||||
|    static timer_ticks get_init_ticks(); | ||||
|    static timer_ticks get_ticks(); | ||||
|    static double ticks_to_secs(timer_ticks ticks); | ||||
|    static inline double ticks_to_ms(timer_ticks ticks) { return ticks_to_secs(ticks) * 1000.0f; } | ||||
|    static inline double get_secs() { return ticks_to_secs(get_ticks()); } | ||||
|    static inline double get_ms() { return ticks_to_ms(get_ticks()); } | ||||
|  | ||||
| private: | ||||
|    static timer_ticks g_init_ticks; | ||||
|    static timer_ticks g_freq; | ||||
|    static double g_inv_freq; | ||||
|  | ||||
|    timer_ticks m_start_time; | ||||
|    timer_ticks m_stop_time; | ||||
|  | ||||
|    bool m_started : 1; | ||||
|    bool m_stopped : 1; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user