Annotation of nono/lib/mystring.cpp, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #include "header.h"
                      7: #include "mystring.h"
                      8: 
                      9: std::string
                     10: string_format(const char *fmt, ...)
                     11: {
                     12:        va_list ap;
                     13:        char *buf;
                     14: 
                     15:        va_start(ap, fmt);
                     16:        vasprintf(&buf, fmt, ap);
                     17:        va_end(ap);
                     18:        std::string rv(buf);
                     19:        free(buf);
                     20: 
                     21:        return rv;
                     22: }
                     23: 
                     24: #if 0
                     25: #include <cstdio>
                     26: #include <sys/time.h>
                     27: int main()
                     28: {
                     29:        std::string s0 = string_format("%d_%d", 0, 1);
                     30:        if (s0 != "0_1") {
                     31:                printf("error\n");
                     32:                return 1;
                     33:        }
                     34:        timeval start, end, result;
                     35:        gettimeofday(&start, NULL);
                     36:        for (int i = 0; i < 100000; i++) {
                     37:                std::string s = string_format("%d_%d", i, i);
                     38:        }
                     39:        gettimeofday(&end, NULL);
                     40:        timersub(&end, &start, &result);
                     41:        long long t = (result.tv_sec) * 1000000 + result.tv_usec;
                     42:        printf("%d.%03d\n", (int)t / 1000, (int)t % 1000);
                     43:        return 0;
                     44: }
                     45: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.