Skip to content
Snippets Groups Projects
Commit cfb77668 authored by Armando Luiz Nicolini Delgado's avatar Armando Luiz Nicolini Delgado :nerd:
Browse files

Pasta 'alt' de 'utils' removida.

parent c38ab04b
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
int main ()
{
char vetor_01[5], var_01;
int vetor_02[6], var_02;
float vetor_03[7], var_03;
double vetor_04[6], var_04;
long int var_05;
long long int var_06;
short int var_07;
struct cls {
int a;
char b[5];
int c[10];
};
printf("\n");
printf("\n");
printf("\n");
printf(" ================================== \n");
printf("| TIPO | TAMANHO EM BYTES |\n");
printf("|==================================|\n");
printf("| char | %2lu |\n", sizeof(char));
printf("| int | %2lu |\n", sizeof(int));
printf("| unsig int | %2lu |\n", sizeof(unsigned int));
printf("| short int | %2lu |\n", sizeof(short int));
printf("| long int | %2lu |\n", sizeof(long int));
printf("| long long int | %2lu |\n", sizeof(long long int));
printf("| float | %2lu |\n", sizeof(float));
printf("| double | %2lu |\n", sizeof(double));
printf("| long double | %2lu |\n", sizeof(long double));
printf("| struct cls | %2lu |\n", sizeof(struct cls));
printf(" ==================================|\n");
printf("| void * | %2lu |\n", sizeof(void *));
printf("| char * | %2lu |\n", sizeof(char *));
printf("| int * | %2lu |\n", sizeof(int *));
printf("| short int * | %2lu |\n", sizeof(short int *));
printf("| long int * | %2lu |\n", sizeof(long int *));
printf("| float * | %2lu |\n", sizeof(float *));
printf("| double * | %2lu |\n", sizeof(double *));
printf("| long double * | %2lu |\n", sizeof(long double *));
printf(" ================================== \n");
printf("\n");
printf("\n");
printf(" ====================================== \n");
printf("| VARIAVEL | TAMANHO EM BYTES |\n");
printf("|======================================|\n");
printf("| char v[5] | %2lu |\n", sizeof vetor_01 );
printf("| int v[6] | %2lu |\n", sizeof vetor_02 );
printf("| float v[7] | %2lu |\n", sizeof vetor_03 );
printf("| double v[6] | %2lu |\n", sizeof(vetor_04));
printf("| char var | %2lu |\n", sizeof var_01 );
printf("| int var | %2lu |\n", sizeof var_02 );
printf("| short int var | %2lu |\n", sizeof(var_07));
printf("| long int var | %2lu |\n", sizeof(var_05));
printf("| long long int var | %2lu |\n", sizeof(var_06));
printf("| float var | %2lu |\n", sizeof var_03 );
printf("| double var | %2lu |\n", sizeof(var_04));
printf(" ====================================== \n");
printf("\n");
printf("\n");
}
#include <stdio.h>
#define BITCOUNT(x) (((BX_(x) + (BX_(x) >> 4)) & 0x0F0F0F0F) % 255)
#define BX_(x) ((x) - \
(((x) >> 1) & 0x77777777) - \
(((x) >> 2) & 0x33333333) - \
(((x) >> 3) & 0x11111111))
int main ()
{
char var_01 = 0x80;
int var_02 = 0x8000;
long int var_05 = 0x800000;
long long int var_06 = 0x800000000000;
short int var_07 = 0x8000;
printf("\n");
printf("\n");
printf(" ====================================== \n");
printf("| VARIAVEL | TAMANHO EM BITS |\n");
printf("|======================================|\n");
printf("| char var | %2d |\n", BITCOUNT(var_01) );
printf("| int var | %2d |\n", BITCOUNT(var_02) );
printf("| short int var | %2lu |\n", sizeof(var_07));
printf("| long int var | %2lu |\n", sizeof(var_05));
printf("| long long int var | %2lu |\n", sizeof(var_06));
printf(" ====================================== \n");
printf("\n");
printf("\n");
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main ()
{
printf("%lu %lu %lu %lu %lu\n", sizeof(long long int), sizeof(long int), sizeof(int), sizeof(short int), sizeof(char));
return 0;
}
#include <stdio.h>
#include "utils.h"
/* Retorna tempo em milisegundos
Forma de uso:
double tempo;
tempo = timestamp();
<trecho de programa do qual se deseja medir tempo>
tempo = timestamp() - tempo;
*/
double timestamp(void)
{
struct timeval tp;
gettimeofday(&tp, NULL);
// printf("\n*** %7.10lf ms %7.10lf ms\n", tp.tv_sec*1.0e3, tp.tv_usec*1.0e-3);
return((double)(tp.tv_sec*1.0e3 + tp.tv_usec*1.0e-3));
}
#ifndef __UTILS_H__
#define __UTILS_H__
#include <stdlib.h>
#include <sys/time.h>
double timestamp(void);
#endif // __UTILS_H__
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "utils.h"
/* Retorna tempo em milisegundos
Forma de uso:
double tempo;
tempo = timestamp();
<trecho de programa do qual se deseja medir tempo>
tempo = timestamp() - tempo;
*/
double timestamp(void)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
return((double)(tp.tv_sec*1.0e3 + tp.tv_nsec*1.0e-6));
}
string_t markerName(string_t baseName, int n)
{
string_t mark = (string_t) malloc( (strlen(baseName)+1) + (log10(n)+1) + 1 );
sprintf(mark, "%s_%u", baseName,n);
// printf("*** %s\n", mark);
return mark;
}
#ifndef __UTILS_H__
#define __UTILS_H__
#include <stdlib.h>
#include <time.h>
typedef double real_t;
typedef double rtime_t;
typedef char * string_t;
double timestamp(void);
string_t markerName(string_t baseName, int n);
#endif // __UTILS_H__
// by W.Zola (2017)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "utils.h"
/* Retorna tempo em nanosegundos
Forma de uso:
chronometer_t *tempo;
chrono_reset( &tempo);
chrono_start( &tempo);
<trecho de programa do qual se deseja medir tempo>
chrono_stop( &tempo);
chrono_reportTime( &tempo, "Tempo: ");
*/
void chrono_reset( chronometer_t *chrono )
{
chrono->xtotal_ns = 0;
chrono->xn_events = 0;
}
void chrono_start( chronometer_t *chrono ) {
clock_gettime(CLOCK_MONOTONIC_RAW, &(chrono->xadd_time1) );
}
void chrono_stop( chronometer_t *chrono ) {
clock_gettime(CLOCK_MONOTONIC_RAW, &(chrono->xadd_time2) );
long long ns1 = chrono->xadd_time1.tv_sec*1.0e9 + chrono->xadd_time1.tv_nsec;
long long ns2 = chrono->xadd_time2.tv_sec*1.0e9 + chrono->xadd_time2.tv_nsec;
chrono->deltaT_ns = ns2 - ns1;
}
void chrono_reportTime( chronometer_t *chrono, char *prompt ) {
printf("\n%s (ns): %llu ns\n", prompt, chrono->deltaT_ns);
}
#ifndef __UTILS_H__
#define __UTILS_H__
// by W.Zola (2017)
#include <time.h>
typedef struct {
struct timespec xadd_time1, xadd_time2;
long long deltaT_ns;
} chronometer_t;
/* Retorna intervlo de tempo em nanosegundos
Forma de uso:
chronometer_t *tempo;
chrono_reset( &tempo);
chrono_start( &tempo);
<trecho de programa do qual se deseja medir tempo>
chrono_stop( &tempo);
chrono_reportTime( &tempo, "Tempo: ");
*/
void chrono_reset( chronometer_t *chrono );
void chrono_start( chronometer_t *chrono );
void chrono_stop( chronometer_t *chrono );
void chrono_reportTime( chronometer_t *chrono, chr *prompt );
#endif // __UTILS_H__
......@@ -33,3 +33,8 @@ string_t markerName(string_t baseName, int n)
}
int isPot2(int n)
{
int k;
return (k = log2(n)) == log2(n) ;
}
......@@ -11,6 +11,7 @@ typedef char * string_t;
double timestamp(void);
string_t markerName(string_t baseName, int n);
int isPot2 (int n);
#endif // __UTILS_H__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment