입력 속도 비교

여러가지 언어와 입력 방법을 이용해서 시간이 얼마나 걸리는지 비교해 보았습니다.

방법: 첫째 줄에 정수의 개수 N (= 10,000,000), 둘째 줄부터 N개의 줄에 한 개의 자연수(10,000 이하)가 적힌 파일을 입력받는데 걸리는 시간을 측정. 10번 측정해서 평균값으로 순위를 매김

순위 언어 입력 방법 평균 (초)
1 C11 mmap 0.043
2 C11 fread 0.0799
3 C11 getchar 0.3496
4 C++17 ios_base::sync_with_stdio(false); cin.tie(NULL); 0.5938
5 C++17 ios_base::sync_with_stdio(false); 0.6348
6 Java BufferedReader, Integer.parseInt 0.6585
7 C11 scanf 0.9206
8 PyPy int(sys.stdin.readline()) 0.9229
9 PyPy map(int,os.read(0, 100000000).split('\n')) 1.1169
10 PyPy3 map(int,os.read(0, 100000000).decode('utf-8').split('\n')) 1.5408
11 PyPy int(raw_input()) 1.925
12 C++17 cin.tie(NULL); 2.059
13 C++17 cin 2.1742
14 C# 6.0 int.Parse(Console.ReadLine()) 2.9635
15 Python 3 map(int,os.read(0, 100000000).decode('utf-8').split('\n')) 4.4033
16 Python 3 int(sys.stdin.readline()) 4.4394
17 Java Scanner 4.8448
18 Python 2 map(int,os.read(0, 100000000).split('\n')) 4.8553
19 Python 2 int(sys.stdin.readline()) 5.7471
20 PyPy3 int(sys.stdin.readline()) 6.6291
21 Python 2 int(raw_input()) 8.9765
22 Python 3 int(input()) 12.4443
23 PyPy3 int(input()) 17.3772
24 Python 2 input() 37.7823
25 PyPy input() 110.3676

언어 정보

  • C11
    • gcc (GCC) 7.2.0
    • gcc a.c -o bin/a -O2 -std=c11
  • C++17
    • g++ (GCC) 7.2.0
    • g++ a.cpp -o bin/a -O2 -std=c++17
  • Java
    • javac 1.8.0_151
    • javac Main.java
  • Python 2
    • Python 2.7.14
    • python a.py
  • PyPy
    • PyPy 5.10.0 with GCC 6.2.0 20160901
    • pypy a.py
  • Python 3
    • Python 3.6.3
    • python3 a.py
  • PyPy3
    • PyPy 5.10.0 with GCC 6.2.0 20160901
    • pypy3 a.py
  • C# 6.0
    • Mono C# compiler version 4.2.1.0
    • mcs -codepage:utf8 -warn:0 -optimize+ -checked+ -clscheck- -reference:System.Numerics.dll Main.cs
    • mono --optimize=all Main.exe

댓글 (5개) 댓글 쓰기


sgchoi5 6년 전

좋은자료감사합니다~


leehosu01 6년 전

혹시 코드내용 공개해주실수있나요? mmap 으로 입력 받고싶은데 다른데에서 예시 코드들을 알아보기 힘들어서요.


baekjoon 6년 전

코드 공개가 가능하기는 한데, mmap만 빼고 가능합니다. mmap은 제가 잘 몰라서 BOJ 어떤 유저분껄로 테스트한거라서요.


y103kim 6년 전

mmap으로 입력받는 코드 참고하세요 http://doocong.com/algorithm/fast-input-mmap/


cr3218 2년 전

좋은자료 정말 감사합니다!!