Created
July 15, 2014 15:02
-
-
Save hiragram/3370a92c66561de5be2b to your computer and use it in GitHub Desktop.
MySQLのDateTimeの形のstringをC++でソートするときタイムスタンプにするのとハイフンコロン取っ払うのとでどっちが速いのか → タイムスタンプ1.7秒、正規表現15秒
This file contains hidden or 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> | |
| #include <string> | |
| #include <regex> | |
| using namespace std; | |
| long long int getIntValueFromDateString(string calendar_date); | |
| int main() | |
| { | |
| string calendar_date = "2014-04-01 06:00:00"; | |
| for(int i = 0 ; i < 1000000 ; i++) | |
| { | |
| getIntValueFromDateString(calendar_date); | |
| } | |
| } | |
| long long int getIntValueFromDateString(string calendar_date) | |
| { | |
| regex pattern("\\D"); | |
| string result = regex_replace(calendar_date , pattern , ""); | |
| return stoll(result); | |
| } |
This file contains hidden or 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> | |
| #include <string> | |
| using namespace std; | |
| int getTimestampFromDateString(string calendar_date); | |
| int main() | |
| { | |
| string calendar_date = "2014-04-01 06:00:00"; | |
| for(int i = 0 ; i < 1000000 ; i++) | |
| { | |
| getTimestampFromDateString(calendar_date); | |
| } | |
| } | |
| int getTimestampFromDateString(string calendar_date) | |
| { | |
| struct tm tmlol; | |
| strptime(calendar_date.c_str() , "%Y-%m-%d %H:%M:%S" , &tmlol); | |
| time_t t = mktime(&tmlol); | |
| return t; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment