Git Product home page Git Product logo

lang_count's Introduction

One bilion counter

NodeJS

Execution time: 0.49572s

node app
console.time("count");

let i = 1000000000;
while (i > 0) {
  i--;
}

console.timeEnd("count");

Rust

Execution time: 0.000000131s

cargo run --release
use std::time::Instant;

fn main() {
    let start: Instant = Instant::now();
    let mut count: u32 = 1_000_000_000;

    while count > 0 {
        count -= 1;
    }
    let elapsed: f64 = start.elapsed().as_secs_f64();

    println!("{}", elapsed);
}

C

Execution time: 0.000000s

gcc -O2 -o count  main.c 
#include <stdio.h>
#include <time.h>

int main()
{
    unsigned long count = 1000000000;
    time_t start_t, end_t;
    double diff_t;

    time(&start_t);
    while (count > 0)
    {
        count--;
    }
    time(&end_t);
    diff_t = difftime(end_t, start_t);

    printf("%f", diff_t);

    return 0;
}

C#

Execution time: 1.6082110s

dotnet new console -o csharp
dotnet build --configuration Release
dotnet run --property:Configuration=Release
var start = DateTime.Now;
ulong count = 1000000000;

while (count > 0)
{
    count--;
}

var stop = DateTime.Now;
Console.WriteLine(stop - start);

C++

execution time: 0s

g++ -O2 -o count main.cpp 
#include <chrono>
#include <iostream>

using namespace std::chrono;

int main()
{
    auto start = high_resolution_clock::now();
    unsigned long count = 1000000000;

    while (count>0){
        count--;
    }

    auto end = high_resolution_clock::now();
    auto elapsed = duration_cast<microseconds>(end - start);

    std::cout << "Count: " << elapsed.count();

    return 0;
}

Python

lang_count's People

Contributors

mariolazzari avatar

Watchers

 avatar

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.