使用并发性提高搜索效率

时间:2018-04-30 16:18:49

标签: go search concurrency goroutine

我有两种方法可以在搜索路径(例如function breezer_addDivToImage( $content ) { if ( is_page_template('single.php') ) { // A regular expression of what to look for. $pattern = '/(<img([^>]*)>)/i'; // What to replace it with. $1 refers to the content in the first 'capture group', in parentheses above $replacement = '<div class="myphoto">$1</div>'; // run preg_replace() on the $content $content = preg_replace( $pattern, $replacement, $content ); // return the processed content return $content; } else { return $content; } } add_filter( 'the_content', 'breezer_addDivToImage' ); )下搜索具有名称模式的文件(例如,*.go用于查找所有go文件)。第一种方法使用递归+ goroutine,第二种方法使用队列来防止可能的堆栈溢出问题。从我在我自己的计算机/Users/username/Desktop上测试得到41,233个go文件,第一种方法比第二种方法快4秒,分别为18秒和22秒。

我想知道是否有更好的方式/并行性使搜索更有效率,因为我正在将搜索集成到桌面应用程序中,我不希望用户坐在那里等待30秒才能看到任何搜索结果。

Desktop

0 个答案:

没有答案