clock and progressbar tests
This commit is contained in:
parent
92f7e73b20
commit
71a946ecf0
@ -127,8 +127,12 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\progressbar test\progressbar.c" />
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\progressbar test\progressbar.h" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -18,5 +18,13 @@
|
|||||||
<ClCompile Include="main.c">
|
<ClCompile Include="main.c">
|
||||||
<Filter>Исходные файлы</Filter>
|
<Filter>Исходные файлы</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\progressbar test\progressbar.c">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\progressbar test\progressbar.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
44
clock/main.c
44
clock/main.c
@ -1,16 +1,50 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include "../progressbar test/progressbar.h"
|
||||||
|
|
||||||
|
// \033[ = CSI, CSI ?25l hides the cursor, CSI ?25h shows the cursor
|
||||||
|
// see ANSI escape code wiki for more info
|
||||||
|
#define HIDE_CURSOR "\033[?25l"
|
||||||
|
#define SHOW_CURSOR "\033[?25h"
|
||||||
|
|
||||||
|
void wait(int seconds) {
|
||||||
|
clock_t t0 = clock();
|
||||||
|
clock_t t1;
|
||||||
|
while ((int)(((t1 = clock()) - t0) / CLOCKS_PER_SEC) < seconds) {
|
||||||
|
Sleep(50);
|
||||||
|
}
|
||||||
|
printf(" wait for %d s is over, clock=%d", seconds, (int)t1);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int n = 10, sl = 10, last_clock = 0;
|
|
||||||
|
#ifdef WIN32
|
||||||
|
printf("ITS WINDOWS!\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct progressbar pb;
|
||||||
|
int n = 5, sl = 1;
|
||||||
|
printf(HIDE_CURSOR);
|
||||||
|
progressbar_start(&pb, n * sl);
|
||||||
|
|
||||||
clock_t start = clock();
|
clock_t start = clock();
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
printf_s("%d\n", i);
|
wait(sl);
|
||||||
Sleep(sl);
|
//printf("%d\n", i);
|
||||||
|
progressbar_add(&pb, sl);
|
||||||
|
}
|
||||||
|
//progressbar_clear();
|
||||||
|
printf(SHOW_CURSOR);
|
||||||
|
printf("\n");
|
||||||
|
printf_s("time = %.3lf seconds\nexpected %d seconds\n", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl);
|
||||||
|
|
||||||
|
progressbar_start(&pb, n * sl);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
wait(sl);
|
||||||
|
//printf("%d\n", i);
|
||||||
|
progressbar_add(&pb, sl);
|
||||||
}
|
}
|
||||||
printf_s("time = %.3lf seconds\nexpected %d seconds %lf", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl / 1000, 0.3300000000000000000000);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -44,6 +44,7 @@ int main() {
|
|||||||
printf("strchr_my_arr_res 's' = {%p} = '%c', index = %d\n", strchr_my_arr_res, *strchr_my_arr_res, (int)(strchr_my_arr_res - test3));
|
printf("strchr_my_arr_res 's' = {%p} = '%c', index = %d\n", strchr_my_arr_res, *strchr_my_arr_res, (int)(strchr_my_arr_res - test3));
|
||||||
char* strchr_my_arr_ptr = strchr_my_ptr(test3, 's');
|
char* strchr_my_arr_ptr = strchr_my_ptr(test3, 's');
|
||||||
printf("strchr_my_arr_ptr 's' = {%p} = '%c', index = %d\n", strchr_my_arr_ptr, *strchr_my_arr_ptr, (int)(strchr_my_arr_ptr - test3));
|
printf("strchr_my_arr_ptr 's' = {%p} = '%c', index = %d\n", strchr_my_arr_ptr, *strchr_my_arr_ptr, (int)(strchr_my_arr_ptr - test3));
|
||||||
|
char dest[10];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// see progressbar.h
|
// see progressbar.h
|
||||||
|
|
||||||
static const unsigned progressbar_width = 70;
|
static const unsigned progressbar_width = 80 - 7;
|
||||||
|
|
||||||
static unsigned get_to_print(unsigned current, unsigned max) {
|
static unsigned get_to_print(unsigned current, unsigned max) {
|
||||||
return progressbar_width * current / max;
|
return progressbar_width * current / max;
|
||||||
@ -54,8 +54,7 @@ void progressbar_inc(struct progressbar *pb) {
|
|||||||
progressbar_add(pb, 1);
|
progressbar_add(pb, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void progressbar_clear(struct progressbar *pb) {
|
void progressbar_clear() {
|
||||||
(void)pb;
|
|
||||||
printf("\r");
|
printf("\r");
|
||||||
for(unsigned i = 0; i < progressbar_width + 7; i++) {
|
for(unsigned i = 0; i < progressbar_width + 7; i++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
@ -15,6 +15,6 @@ void progressbar_add(struct progressbar *pb, unsigned n);
|
|||||||
// add one to current value
|
// add one to current value
|
||||||
void progressbar_inc(struct progressbar *pb);
|
void progressbar_inc(struct progressbar *pb);
|
||||||
// clear line of progress bar
|
// clear line of progress bar
|
||||||
void progressbar_clear(struct progressbar *pb);
|
void progressbar_clear();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user