Last active
February 11, 2024 12:05
-
-
Save alexaleluia12/a470b709d0034b37de90 to your computer and use it in GitHub Desktop.
Benchmarck (comparação de velocidade) Python, C, Java, Javascript, C++, Kotlin, Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
machine: | |
alex@alex-Aspire-V3-571:~$ lscpu | |
Arquitetura: x86_64 | |
Modo(s) operacional da CPU32-bit, 64-bit | |
Byte Order: Little Endian | |
CPU(s): 4 | |
On-line CPU(s) list: 0-3 | |
Thread(s) per núcleo 2 | |
Núcleo(s) por soquete:2 | |
Soquete(s): 1 | |
Nó(s) de NUMA: 1 | |
ID de fornecedor: GenuineIntel | |
Família da CPU: 6 | |
Modelo: 58 | |
Step: 9 | |
CPU MHz: 2601.000 | |
BogoMIPS: 5187.86 | |
Virtualização: VT-x | |
cache de L1d: 32K | |
cache de L1i: 32K | |
cache de L2: 256K | |
cache de L3: 3072K | |
NUMA node0 CPU(s): 0-3 | |
python 2.7: | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time python python.py | |
499500 | |
real 0m0.019s | |
user 0m0.008s | |
sys 0m0.011s | |
python 3.4: | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time python3 python.py | |
499500 | |
real 0m0.025s | |
user 0m0.025s | |
sys 0m0.000s | |
c: | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time ./c-lang | |
499500 | |
real 0m0.002s | |
user 0m0.000s | |
sys 0m0.001s | |
js | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time node nodejs.js | |
499500 | |
real 0m0.047s | |
user 0m0.040s | |
sys 0m0.008s | |
java7 | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time java Java | |
499500 | |
real 0m0.077s | |
user 0m0.066s | |
sys 0m0.012s | |
c++ | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ g++ -std=c++11 cpp.cpp -o cpp | |
alex@alex-Aspire-V3-571:~/Documentos/cod-cursos/benchmark$ time ./cpp | |
499500 | |
real 0m0.003s | |
user 0m0.002s | |
sys 0m0.000s | |
ruby # contribuition from ruannawe | |
ruan@ruan-Inspiron-5457:~/Documents/ruby$ ruby executiontime.rb | |
499500 | |
user: 0.000046 | |
system: 0.000007 | |
total: 0.000053 | |
real: 0.000053 | |
kotlin 1.3 | |
alex@pc:~/workspace/scripts$ kotlinc kotlin.kt | |
alex@pc:~/workspace/scripts$ time java KotlinKt | |
499500 | |
real 0m0,058s | |
user 0m0,071s | |
sys 0m0,009s | |
go 1.12 | |
alex@pc:~/workspace/scripts$ time ./bm | |
499500 | |
real 0m0,003s | |
user 0m0,000s | |
sys 0m0,004s | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var count = 0 | |
for i:=0; i < 1000; i++ { | |
count += i | |
} | |
fmt.Printf("%d\n", count) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
int count = 0; | |
int i = 0; | |
for(i; i<1000; i++){ | |
count += i; | |
} | |
printf("%d", count); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Eu já tinha visto alguns desses testes antes. | |
E também até já ouvi falar que Java é mais rápido do que C. | |
E que Python é lento. | |
Nada é melhor do que faça você mesmo para tirar suas conclusões. | |
Meu computador é um Acer com OS gnu-linux (Ubuntu-14.04), processador i5. | |
Conclusão: | |
Eu gosto bastaste de Python mas não tem um bom suporte para multicore. | |
Kotlin pode ser um excelente escolha para desenvolver Aplicações e Go para Sistemas. | |
A velocidade de linguages baseadas na JVM pode melhorar consideralvmente com Graaval. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main (){ | |
unsigned int i, count=0; | |
for(i=0; i<1000; ++i){ | |
count += i; | |
} | |
std::cout << count << std::endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Java { | |
public static void main(String[] args) { | |
int count = 0; | |
for(int i=0; i<1000; i++){ | |
count += i; | |
} | |
System.out.println(count); // corrigido conforme comentario | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
var count = 0 | |
repeat(1000) { | |
count += it | |
} | |
println(count) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var count = 0; | |
for(var i=0; i<1000; i++) | |
count += i; | |
console.log(count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
count = 0 | |
for i in range(1000): | |
count += i | |
print(count) |
Podia ter feito computações mais agressivas, multiplicações de matrizes por exemplo. Em um programa tão simples, Python e principalmente Java levam desvantagem
@pmatos2000 nada especial em usar esse tipo em C++, mas ele cabe perfeitamente nesse caso.
Porque são inteiros positivos.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O Java não precisava somar o número em uma string, poderia ser direto System.out.println(count);
Isso não mudaria muito o desempenho, eu acho kkkk...
Em C++ tem algum objetivo de usar o unsigned int i ?