Coder Social home page Coder Social logo

Comments (3)

julian-salinas avatar julian-salinas commented on September 9, 2024

Hola! Cómo va? Ví tu issue y se me ocurrio una forma de implementar esto que mencionás y desarrollé una solución en un fork, si te parece, fijate si es en lo que estabas pensando :)

Mi idea fue crear una variable de tipo t_temporal que maneje milisegundos, sobre esa variable es posible obtener el tiempo desde que fué inicializada, calcular la diferencia con una variable del mismo tipo, poder pausarla y reanudarla cuando uno quiera.

saludos!

from so-commons-library.

RaniAgus avatar RaniAgus commented on September 9, 2024

¡Buenas @julian-salinas!

Genioo 🎉, mandanos un Pull Request y cuando tenga un ratito te hago code review 😉

También si podés subir un par de tests a tests/integration-tests con casos de uso simulados con sleeps a modo de ejemplo sería un golazo, se me ocurre algo tipo:

void test_temporal_gettime() {
    t_temporal *temporal = temporal_create();
    sleep(2);
    
    printf("test_temporal_gettime: %ldms (expected: ~2000ms)\n", temporal_gettime(temporal));

    temporal_destroy(temporal);
}

void test_temporal_stop() {
    t_temporal *temporal = temporal_create();
    sleep(1);
    temporal_stop(temporal);
    sleep(2);

    printf("test_temporal_stop: %ldms (expected: ~1000ms)\n", temporal_gettime(temporal));

    temporal_destroy(temporal);
}


void test_temporal_resume() {
    // detendría y reiniciaría el temporal un par de veces
}


void test_temporal_diff() {
    // crearía 2 temporal, los detendría en distintos momentos y los compararía
}

// algún otro caso de uso?

int main() {
   test_temporal_gettime();
   test_temporal_stop();
   test_temporal_resume();
   test_temporal_diff();
   ...
}

No los pondría en tests/unit-tests porque entiendo que es difícil hacerlo determinísitico, y si incluimos sleeps las pruebas tardarían bastante como para ser unitarias.

Abrazo

from so-commons-library.

julian-salinas avatar julian-salinas commented on September 9, 2024

Genial! Gracias Agus!

from so-commons-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.