问题标签 [processing-efficiency]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - Efficient method to check for matching files in Java
I'm no Java expert but the program I'm making is going to be dealing with high throughput. So I thought I'd do a little crowd sourcing for opinions. Here's the situation.
A java process will be watching a directory for files to process, these files will be paired (data file to be stored and xml file with meta information to be cataloged). So I need to get the list of current files, check for the required twins, and then process.
Files will always have matching filenames and only differ by file extension e.g. filename1.jpg filename1.xml filename2.jpg filename2.xml
I have three options I've thought of so far.
Use FilenameFilter with File.List(FileNamefilter) call to check if the total files with a filename is greater than 1.
Use two filenamefilters to generate a list of files with .xml and without .xml, convert the non XML file list to an ArrayList and call Collections.binarySearch().
Generate a list of all files without .xml extension, use this list as the keys for a hashmap of key/value pairs that assumes the .xml file based on the filename. Then run through the hash list and check for the existence of the .xml twin before processing.
Any thoughts?
EDITS/COMMENTS
After looking at the suggestions and tinkering I'm for now going with using two FilenameFilters, one that lists XML files and one that does not. The list of XML files is stripped of the xml extension and dumped into a hash. Then the list of data files is iterated through, calling hashlist.contains() to see if a match exists in the hashset before proceeding.
There is the concern as mentioned below of processing incomplete files. As I said in comments, I assume that a newly written file is not visible to non-writing processes until that write is complete (new files, not open for edit)
c# - C# SQL Server - 对多个数据库访问或通过数据的多个循环更有效?
在我的应用程序的一部分中,我必须获取满足条件的表的最后一个 ID 例如:
所以我可以抓取整个表并循环查找 Num = 2,或者我可以从 Num = 2 的表中抓取数据。在后者中,我知道最后一项将是 MAX ID。
无论哪种方式,我都必须这样做大约 50 次......所以抓取所有数据并循环遍历数据列表以寻找特定条件会更有效......
还是根据条件多次获取数据会更好..我知道列表中的最后一项将是最大 id
我有 6 个条件,我必须根据这些条件进行查询
我只是想知道哪个更有效...循环遍历大约 3500 个项目的列表几次,或者多次访问数据库,我已经可以像我需要的那样分解数据
iphone - 核心数据效率
将 4 种类型的属性存储到 Core Data 中的 32 位 int 中是否有点矫枉过正?或者我应该为它们中的每一个简单地创建一个单独的属性?(将使用逻辑运算符来设置/获取)。
我计划向现有对象添加一个新实体,该对象将包含 200-400 个具有大约 14 个属性的项目(包括用于排序目的的“索引”属性)。任何时候都只能操作或查看一套。
我需要维护撤消支持(参考How do I raise performance of Core Data object insert on iPhone?)
如果我将多个属性存储到一个字段中,我可以将其减少到大约 8 个属性。除非存在可搜索性问题,否则我会节省大量空间吗?
此外,将一组 400 个对象存储在以每周 1-3 个左右的速度增长的项目列表中是否不合理?
我听说有些人在核心数据中存储了数千个项目,所以我可能是偏执狂。我想从长远来看,我需要提供一个导出存档选项,也许是 iCloud。
iphone - CALayer的效率和极限是多少
在我的 iPhone 应用程序中,我需要显示大量(最多 150 个)10x10 像素的小点,它们分别在屏幕上移动。它们不需要以任何方式顺利移动,但需要每秒钟左右更新一次。目前,我已将其实现为一个每秒重绘的 CALayer。
但我知道 CALayers 非常高效,因为它们映射到 GPU 硬件。所以我想知道为每个点创建一个单独的 CALayer 并通过设置它们的位置属性来移动它是否会更有效(就电池使用而言)。
所以我想知道你是否有这方面的经验。CPU 可以做的更少,但 GPU 更多。GPU硬件仍然可以处理多少个CALayer?
如果我让它们分开 CALayers,我也可以轻松地为它们设置动画,这样看起来会更好。那会更耗能吗?
在我的情况下更糟糕的是,我目前为它们使用 CATiledLayer,最多暴露 4 个图块。这也意味着我每次更新都需要重绘它们 4 次。
performance - 迭代深化还是反复试验?
我正在编写棋盘游戏。我使用 alpha-beta 修剪生成了一个游戏树,并有 2 个选项:
- 使用迭代深化来优化 alpha-beta,使其不断生成一层,直到时间结束。
- 通过反复试验,我知道在时间限制内每个板配置可达到的最大深度,而无需事先检查下层。
哪种方法更好,并且会使搜索达到更深的深度?例如,我知道,一开始我可以生成一棵深度为 X 的树,消耗所有可用的时间......迭代加深可以增加更多深度吗?
让我知道我是否可以更清楚...
python - 使用 cython 加速耗时的列表操作
我有一个函数,它将 numpy ndarray 中表示的图像作为参数。此 ndarray 由一个列表x列表x列表项(行 x 像素 x 像素)组成,需要转换为常规列表格式的列表x列表x元组(因此不再作为 ndarray)。
因此,例如这个变量的内容可能看起来像
并且应该变成:
下面的(cython)代码段正是这样做的,但完成一个 1024x768 的图像需要大约 800 毫秒。
我的问题是:我可以通过哪些方式使这段代码更(时间)高效?我已经搜索了列表是否有 cdef,但没有找到任何线索。如果我想在 100 毫秒的完成时间内完成它,我希望我不是在要求不可能的事情。在此先感谢您的任何建议。
performance - RavenDB 中哪个最有效:大量的小文档,还是单个大文档?
我需要在 RavenDB 中存储大量(约 50,000 个)小数据。当我读回这些数据时,我每次都会阅读全部内容。写作时,我可以写全部或每篇文章。
数据如下所示:
我可以轻松地将其存储为单个Dictionary<int, long>
而不是Item
对象集合的文档包装器。
这些方法中哪一种在 RavenDB 中更有效?
如果我的数据集增加到〜500,000,效率差异会被夸大(在读取情况下)吗?
java - 当使用单个任务调用 ExecutorService.invokeAll() 时,效率如何(低)?
我有一些代码大量使用线程池,我通过创建Collection<Callable<T>> tasks
和调用来使用线程池ExecutorService.invokeAll(tasks)
。
在我的应用程序中,大小tasks
变化很大。事实上,大多数情况下都是用单个任务ExecutorService.invokeAll()
调用的。我正在使用的实现调用,其实现似乎总是在线程池中运行任务(从不在调用线程中)。invokeAll()
ThreadPoolExecutor.execute()
在单个任务的情况下,在当前线程中调用任务而不是将其发送到另一个线程会更有效吗?
mysql - 对百万行表,MySQL 的 LIKE 查询的性能
从任何有实际经验的人看来,如果字段有一个普通的 INDEX,LIKE 查询如何在数百万行表上的 MySQL 中执行,在速度和效率方面?
是否有更好的替代方法(不过滤结果,如 FULLTEXT 50% 规则)在数百万行表上执行数据库字段搜索?
例子:
udp - 为什么当输入数据大小增加一点时 udp sendto 会变得如此缓慢?
我有一个奇怪的问题。我在android上做了以下测试:
我=0;
而(我< PACKET_NUMBER)
{
//UDP发送数据包
if( sendto(sockfd,buffer,strlen(buffer),0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <= 0)
{
error("通过udp向远程主机发送数据包失败\ n");
}
我++;
}
我用不同的缓冲区大小做了这个测试。当缓冲区大小小于一个数字(应该在 500 字节左右)时,无论我选择哪种大小,例如 20 40 80 160 320 ,while 语句都可以在几乎相同的时间内执行,例如 3 分 10 秒。但是,当数据包大小大于 500 时,例如 510 520 600 1280,while 语句的执行时间要长得多,例如超过 10 分钟。谁能给我一些关于原因的提示?