| 156 | } |
| 157 | |
| 158 | void add(wdb_sess& sess, long long max) { |
| 159 | acl::string key, value; |
| 160 | long long i, n; |
| 161 | |
| 162 | struct timeval begin; |
| 163 | gettimeofday(&begin, NULL); |
| 164 | |
| 165 | for (i = 0; i < max; i++) { |
| 166 | key.format("key-%d-%lld", id_, i); |
| 167 | value.format("value-%lld", i); |
| 168 | bool ret = sess.add(key.c_str(), value.c_str()); |
| 169 | if (!ret) { |
| 170 | printf("add failed, key=%s, value=%s\r\n", |
| 171 | key.c_str(), value.c_str()); |
| 172 | break; |
| 173 | } |
| 174 | n = ++__count; |
| 175 | if (i % __inter == 0) { |
| 176 | char buf[128]; |
| 177 | snprintf(buf, sizeof(buf), "i=%lld, count=%lld, value=%s", |
| 178 | i, n, value.c_str()); |
| 179 | acl::meter_time(__FILE__, __LINE__, buf); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | struct timeval end; |
| 184 | gettimeofday(&end, NULL); |
| 185 | double spent = acl::stamp_sub(end, begin); |
| 186 | double speed = (i * 1000) / ( spent > 1 ? spent : 1); |
| 187 | printf("add over, n=%lld, spent=%.2f seconds, speed=%.2f\r\n", |
| 188 | i, spent / 1000, speed); |
| 189 | } |
| 190 | |
| 191 | void get(wdb_sess& sess, long long max) { |
| 192 | acl::string key, value; |
nothing calls this directly
no test coverage detected