#17603: c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 12:47

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

 
#17605: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 16:18

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

 
#17606: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 16:28

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

 
#17608: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 16:39

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

 
#17613: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 19:34

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

 
#17614: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 19:44

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


 
#17615: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 19:50

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


 
#17616: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 19:53

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

 
#17617: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 19:57

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

 
#17618: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 20:00

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

 
#17619: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 20:06

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include<iostream>

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

 
#17620: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 20:08

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

謝學長,但這算cin嗎?

還有scanf呢?

 
#17621: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 20:13

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

謝學長,但這算cin嗎?

還有scanf呢?

應該算,但不知道會不會對他的速度造成影響
你要做的測試數據應該都在這裡(這網站算是大網站,數據會比較可靠):https://www.irjet.net/archives/V3/i7/IRJET-V3I7326.pdf

 
#17622: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-27 20:14

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

謝學長,但這算cin嗎?

還有scanf呢?

應該算,但不知道會不會對他的速度造成影響
你要做的測試數據應該都在這裡(這網站算是大網站,數據會比較可靠):https://www.irjet.net/archives/V3/i7/IRJET-V3I7326.pdf


喔~~~完全看不懂......

 
#17623: Re:c++中cout和printf速度 大大也一起討論吧!


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.136.179.30]
最後登入時間 :
2024-04-29 19:11:35
. Unfinished! | From: [111.71.17.172] | 發表日期 : 2019-04-27 20:19

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

謝學長,但這算cin嗎?

還有scanf呢?

應該算,但不知道會不會對他的速度造成影響
你要做的測試數據應該都在這裡(這網站算是大網站,數據會比較可靠):https://www.irjet.net/archives/V3/i7/IRJET-V3I7326.pdf


喔~~~完全看不懂......

這我幫不了你.....你就看表格的數據就好


 
#17627: Re:c++中cout和printf速度 大大也一起討論吧!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
. Unfinished! | From: [114.42.218.16] | 發表日期 : 2019-04-28 09:25

探討cout與printf的差別 (五)速度 part5:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part5.html

探討cout與printf的差別 (四)速度 part4:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part4.html

探討cout與printf的差別 (三)速度 part3:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part3.html

探討cout與printf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part2.html

探討cout與printf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/coutprintf-part1-c-include-using.html

為甚麼我自己測試cout加ios::sync_with_stdio(false)會比printf快這麼多?

跟網路上完全不一樣?

大大們告訴小弟我做錯甚麼吧!

我把數字加大到10^6
結果十分令人驚訝...

1~10^6 int (array)                        (output size: 6888864 bytes , 6.569 MB):

  cout+sync off+'\n':27.04 s (1st)

  cout+endl            :232.1 s (2nd)

  cout+'\n'             :269.1 s (3rd)

  printf                  :418.1 s (4th)

 

  10^6 string ("Hello world")             (output size: 12000000 bytes , 11.444 MB):

  cout+sync off+'\n':20.08 s (1st)

  puts                    :98.53 s (2nd)

  cout+'\n'             :143.8 s (3rd)

  cout+endl            :238.4 s (4th)

  printf                   :677.5 s (5th)

  putchar                :691.3 s (6th)

 

  10^6 (int(1~10^6)+string(". Hello world"))(output size: 20888864 bytes , 19.921 MB):

  cout+sync off+'\n':14.56 s (1st)

  cout+'\n'             :219.0 s (2nd)

  cout+endl            :273.5 s (3rd)

  printf                   :956.6 s (4th)

 

  1~10^6 double(precision:3)              (output size: 10888864 bytes , 10.384 MB):

  cout+sync off+'\n':16.87 s (1st)

  cout+endl            :140.3 s (2nd)

  cout+'\n'             :188.5 s (3rd)

  printf                  :549.5 s (4th)

 

1.看的出來我的電腦很慢XD

2.printf真的好慢

printf慢的原因,應該是因為他是格式化輸出,可是還是與本人的經驗相違背

 

那就代表~~~~~

cin,cout簡單又好用XD

還有我的測試沒錯XD

1.你測的只有cout和printf,cin和scanf可沒測
2.我用a007的建表法實測:
cin/cout : 1s

scanf/printf : 0.8s

scanf/puts : 0.7s

cin/cout(ios::sync_with_stdio(0);cin.tie(0);) : 0.7s

所以我說實驗結果與我的經驗相違背

 

我又做了一個測試:

探討cin與scanf的差別 (一)速度 part1:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part1.html

我還在繼續製作相關的測試

我問一下cin要怎麼讀' '和'\n'?


是指怎麼讀一整行嗎?


不,而是:

輸入:

1

1

1

1

1

 

輸出:

1

1

1

1

1

 

(一樣的東西)

(只能用cin,cout)

這可以當良心題了ㄟXD

char c

while(cin>>c){

cout<<c;

}

這樣嗎?

類似,

但cin會吃掉'\n'和' '。

#include

using namespace std;

int main(){

char c;

while(cin.get(c)){

cout<<c;

}

這樣

謝學長,但這算cin嗎?

還有scanf呢?

應該算,但不知道會不會對他的速度造成影響
你要做的測試數據應該都在這裡(這網站算是大網站,數據會比較可靠):https://www.irjet.net/archives/V3/i7/IRJET-V3I7326.pdf


喔~~~完全看不懂......

這我幫不了你.....你就看表格的數據就好


探討cin與scanf的差別 (二)速度 part2:

https://taurenprogram.blogspot.com/2019/04/cinscanf-part2.html

我測過cin和cin.get()了

10000000個1,cin.get()平均比cin快0.1左右(不加速)

 
ZeroJudge Forum