Added a history speed test

Profile driven caching of config directory
Style fixes
This commit is contained in:
ridiculousfish 2012-12-03 02:25:08 -08:00
parent 33fc5c99ea
commit b9283d48b5
7 changed files with 137 additions and 100 deletions

View file

@ -978,6 +978,7 @@ public:
static void test_history(void); static void test_history(void);
static void test_history_merge(void); static void test_history_merge(void);
static void test_history_formats(void); static void test_history_formats(void);
static void test_history_speed(void);
static void test_history_races(void); static void test_history_races(void);
static void test_history_races_pound_on_history(); static void test_history_races_pound_on_history();
@ -1408,6 +1409,32 @@ void history_tests_t::test_history_formats(void)
} }
} }
void history_tests_t::test_history_speed(void)
{
say(L"Testing history speed");
history_t *hist = new history_t(L"speed_test");
wcstring item = L"History Speed Test - X";
/* Test for 10 seconds */
double start = timef();
double end = start + 4;
double stop = 0;
size_t count = 0;
for (;;)
{
item[item.size() - 1] = L'0' + (count % 10);
hist->add(item);
count++;
stop = timef();
if (stop >= end)
break;
}
printf("%lu items - %.2f msec per item\n", (unsigned long)count, (stop - start) * 1E6 / count);
hist->clear();
delete hist;
}
/** /**
Main test Main test
@ -1448,6 +1475,7 @@ int main(int argc, char **argv)
history_tests_t::test_history_merge(); history_tests_t::test_history_merge();
history_tests_t::test_history_races(); history_tests_t::test_history_races();
history_tests_t::test_history_formats(); history_tests_t::test_history_formats();
//history_tests_t::test_history_speed();
say(L"Encountered %d errors in low-level tests", err_count); say(L"Encountered %d errors in low-level tests", err_count);

View file

@ -1308,6 +1308,8 @@ bool history_t::save_internal_via_rewrite()
{ {
/* We've saved everything, so we have no more unsaved items */ /* We've saved everything, so we have no more unsaved items */
this->first_unwritten_new_item_index = new_items.size(); this->first_unwritten_new_item_index = new_items.size();
/* We deleted our deleted items */
this->deleted_items.clear(); this->deleted_items.clear();
/* Our history has been written to the file, so clear our state so we can re-reference the file. */ /* Our history has been written to the file, so clear our state so we can re-reference the file. */
@ -1418,7 +1420,7 @@ void history_t::save_internal(bool vacuum)
ASSERT_IS_LOCKED(lock); ASSERT_IS_LOCKED(lock);
/* Nothing to do if there's no new items */ /* Nothing to do if there's no new items */
if (new_items.empty() && deleted_items.empty()) if (first_unwritten_new_item_index >= new_items.size() && deleted_items.empty())
return; return;
/* Compact our new items so we don't have duplicates */ /* Compact our new items so we don't have duplicates */

View file

@ -323,9 +323,9 @@ bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wch
return result; return result;
} }
bool path_get_config(wcstring &path) static wcstring path_create_config()
{ {
int done = 0; bool done = false;
wcstring res; wcstring res;
const env_var_t xdg_dir = env_get_string(L"XDG_CONFIG_HOME"); const env_var_t xdg_dir = env_get_string(L"XDG_CONFIG_HOME");
@ -334,7 +334,7 @@ bool path_get_config(wcstring &path)
res = xdg_dir + L"/fish"; res = xdg_dir + L"/fish";
if (!create_directory(res)) if (!create_directory(res))
{ {
done = 1; done = true;
} }
} }
else else
@ -345,22 +345,26 @@ bool path_get_config(wcstring &path)
res = home + L"/.config/fish"; res = home + L"/.config/fish";
if (!create_directory(res)) if (!create_directory(res))
{ {
done = 1; done = true;
} }
} }
} }
if (done) if (! done)
{
path = res;
return true;
}
else
{ {
res.clear();
debug(0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access.")); debug(0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access."));
return false;
} }
return res;
}
/* Cache the config path */
bool path_get_config(wcstring &path)
{
static const wcstring result = path_create_config();
path = result;
return ! result.empty();
} }
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement) static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)

View file

@ -768,7 +768,8 @@ static bool test_stuff(screen_t *scr)
sleep(5); sleep(5);
for (size_t i=0; i < 1; i++) { for (size_t i=0; i < 1; i++)
{
writembs(cursor_left); writembs(cursor_left);
} }
@ -780,13 +781,15 @@ static bool test_stuff(screen_t *scr)
while (1) { while (1)
{
int c = getchar(); int c = getchar();
if (c != EOF) break; if (c != EOF) break;
} }
while (1) { while (1)
{
int c = getchar(); int c = getchar();
if (c != EOF) break; if (c != EOF) break;
} }