Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Expandir
titleVerifique o código utilizado
Bloco de código
languagecpp
firstline1
titlemallocio.cpp
linenumberstrue
#include "pch.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;
int main()
{
    void *var = 0;

    time_t timer;
    time_t timer2;
    struct tm y2k = { 0 };
    double seconds;
    string msgret;

    printf("TESTE 1\n");
    printf("ALOCANDO BLOCO DE MEMORIA\n");

    y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
    y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
    timer = time(NULL);

    for (int i = 0; i < 300000000; i++)
    {
        var = malloc(100);
        free(var);
    }

    timer2 = time(NULL);
    seconds = timer2 - timer;

    printf("TEMPO LEVADO PARA ALOCAR MEMORIA: %f segundos\n", seconds);

    printf("TESTE 2\n");
    printf("LEITURA EM DISCO\n");

    y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
    y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
    timer = time(NULL);

    char * buffer;
    FILE *pFile = fopen("teste.txt", "rb");
    long lSize = ftell(pFile);
    size_t result;
    buffer = (char*)malloc(sizeof(char)*lSize);
    for (int i = 0; i < 7000000; i++)
    {
        fseek(pFile, 0, SEEK_END);
        result = fread(buffer, 1, lSize, pFile);
    }
    fclose(pFile);
    free(buffer);
    timer2 = time(NULL);
    seconds = timer2 - timer;

    printf("TEMPO LEVADO PARA REALIZAR A LEITURA EM DISCO: %f segundos\n", seconds);
}
Expandir
titleUtlizando Utilizando o MallocIO

Executando em modo DOS, você acesse o diretório do executável. Você terá a seguinte tela:

Image Added

ALOCANDO BLOCO DE MEMÓRIA

Representam o momento de início da alocação e de final da alocação do bloco de memória. Como resposta, você receberá o tempo de execução.

Tempo para alocar bloco de memória:

10.000000

até

Até 20.000000

Ótimo

21.000000

até

Até 24.000000

Bom

25.000000

até

Até 29.000000

Ruim

Acima de 30.000000

até

40.000000

Péssimo

LEITURA EM DISCO

Representam o momento de início de leitura em um arquivo .txt e o final da leitura. Verifique na tabela de referência se o seu resultado será adequado para o Protheus.

Tempo de leitura do arquivo teste:

Até 10.000000

seconds

segundos

Ótimo

Até 25.000000

seconds

segundos

Bom

Até 26.000000

seconds

segundos

Ruim

Acima de 40.000000

seconds

segundos

Péssimo