哪个MEAN生成器 - javascript(Which MEAN Generator - javascript)
我只是这个领域的新手,我的意思是使用javascript开发网络应用程序。
我正在学习如何在后端使用NodeJS + express,但与此同时我试图继续在前端使用AngularJS。 我还为应用程序的脚手架安装了yeoman; 实际上我正在使用generator-angularexpress。
所以,我的问题是:你认为哪个生成器是Web应用程序脚手架的最佳生成器,请记住我想构建一个MEAN堆栈?
谢谢大家!
I'm just a newbie in this field, I mean at the development of web apps using javascript.
I was learning how to use NodeJS + express on the backend, but at the same time I was trying to go ahead with the use of AngularJS on the front-end. I also installed yeoman for the scaffolding of the app; actually I was using generator-angularexpress.
So, my question is: which generator do you consider to be the best one for the scaffolding of the web app, keeping in mind that I want to build a MEAN stack?
Thank you folks!
原文:https://stackoverflow.com/questions/19287035
最满意答案
我相信最耗时的部分应该是执行查询。 如果你使用
whereIn
,那么我认为你只能执行一次查询,然后遍历结果。 我没有测试过,但它应该是这样的:$purchasesByYear = \App\Inventory::select('purchase_year', DB::raw('count(*) as purchase_count')) ->whereIn('purchase_year', $purchaseYears) ->groupBy('purchase_year')->get();
我认为减少查询执行次数将是阻止其慢慢运行的主要机会。 此外,我认为如果您还没有这样做,那么在purchase_year中添加索引应该会有所帮助。
你可以使用一些数学来代替很多其他条件来处理这些年份的分组。 这实际上可能稍慢,但代码重复性稍差,我相信你对这部分所做的任何事情都将是微观优化,而不是你可以对查询部分做什么。 我的建议:
foreach ($purchasesByYear as $purchaseYear) { $year = $purchaseYear->purchase_year; if ($year < 1960) { $yearRange = 'Pre 1960'; } else { // subtract one until the year is a multiple of five while ($year % 5) { $year--; } // then construct the range string using the starting number $yearRange = $year.'-'.($year+4); } if (isset($chartData[$yearRange])) { $chartData[$yearRange] += $purchaseYear->purchase_count; } else { $chartData[$yearRange] = $purchaseYear->purchase_count; } }
I believe the most time consuming part should be executing the query. If you use
whereIn
, then I think you can execute the query only once, and then loop over the results. I haven't tested it, but it should be something like this:$purchasesByYear = \App\Inventory::select('purchase_year', DB::raw('count(*) as purchase_count')) ->whereIn('purchase_year', $purchaseYears) ->groupBy('purchase_year')->get();
I think reducing the number of query executions will be the main opportunity to keep this from running slowly. Also, I think adding an index to purchase_year should be helpful if you have not already done so.
Instead of a lot of elseif conditions to handle grouping the years, you could use some math. This might actually be slightly slower, but the code would be a little less repetitive, and I believe anything you do to this part will be a micro-optimization compared to what you can do with the query part. My suggestion:
foreach ($purchasesByYear as $purchaseYear) { $year = $purchaseYear->purchase_year; if ($year < 1960) { $yearRange = 'Pre 1960'; } else { // subtract one until the year is a multiple of five while ($year % 5) { $year--; } // then construct the range string using the starting number $yearRange = $year.'-'.($year+4); } if (isset($chartData[$yearRange])) { $chartData[$yearRange] += $purchaseYear->purchase_count; } else { $chartData[$yearRange] = $purchaseYear->purchase_count; } }
相关问答
更多-
TSQL在光标循环中更快(TSQL Faster In Cursor Loop)[2022-02-11]
使用提示能够独立计划看起来像光标计划,并修复了速度问题。 修复查询:(并非一直修复为OPTION失败) select max(list.match) as 'max' from ( SELECT count(*) as 'match' FROM [docSVenum1] with (nolock) INNER LOOP JOIN [FTSindexWordOnce] as w1 with (NOLOCK, FORCESEEK) ... -
不比其他方法更好,但你也可以在每个方向上使用np.roll来做同样的事情: def evolve_heat_slow(u): u2 = u.copy() u2[1:-1, 1:-1] = ((np.roll(u2,1,0) + np.roll(u2,-1,0) + np.roll(u2,1,1) + np.roll(u2,-1,1))/4)[1:-1, 1:-1] return u2 现在用u2 = evolve_heat_slow ...
-
如何使R循环更快?(How to make R loop faster?)[2022-06-17]
这绝不是优雅的,但似乎有效: library(jsonlite) library(purrr) library(dplyr) json_data <- '[{"data":{"id":"3f066cdd81cf4944b42230ed56a35bce","awards":[{"status":"unsuccessful","value":{"amount":76}},{"status":"active","value":{"amount":41220}}],"value":{"amount":48000} ... -
基准 这个自制的随机基准测试表明,在大多数情况下,使用in的解决方案明显更快。 我没有调查,但我确实遇到了一些运行,其中嵌套for循环的解决方案在使用样本大小时稍快。 import time, random def time_it(f, rep=100000): sample = [[random.randint(0, 100) for _ in range(20)] for _ in range(rep // 100)] start = time.time() for i in ...
-
通过使用同步和异步,速度不会受到任何影响。 互联网的速度是一样的。 问题是你绝不能在主线程上进行同步网络调用。 这样做会锁定用户界面。 最好的情况是你的应用出现锁定到用户(坏)。 更糟糕的是,操作系统杀死你的应用程序无响应(坏)。 所有的联网应该在后台完成。 如果你的应用程序在所有的网络访问完成之后才能真正进行,至少你可以建立一个“忙碌”的屏幕,让用户知道发生了什么。 也许使用进度条让用户知道进程有多远,或者显示文件数量的“x of y”计数。 什么是适合你的应用程序。 但同样,网络访问的速度不会改变。 您 ...
-
如果你考虑一下,那么.hasOwnProperty()方法会更快,因为它只使用1 for loop 。 错误 我其实有点惊讶。 我期待双循环更慢。 但我想你无法估计for loop的速度。 双循环 虽然这对我来说似乎是最慢的,但这实际上最终成为7,291,083 ops/sec的最快7,291,083 ops/sec .hasOwnProperty() 我可以看到这会慢,因为函数比语句慢。 这个1,730,588 ops/sec为1,730,588 ops/sec if..in @Geuis回答包括if.. ...
-
如何通过多线程更快速地制作Java for循环?(How do I make a slow Java for loop faster with multithreading?)[2023-05-07]
这有点宽泛,但是当处理器数量大于1并且slowMethod是独立的时,使用具有固定线程号的ExecutorService会使其更快。 如果slowMethod是I / O密集型,则可以增加线程数以获得更高的性能。 import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Main { public static void main(String[] args) ... -
如何让这个循环更快?(How can I make this loop faster?)[2023-09-23]
我相信最耗时的部分应该是执行查询。 如果你使用whereIn ,那么我认为你只能执行一次查询,然后遍历结果。 我没有测试过,但它应该是这样的: $purchasesByYear = \App\Inventory::select('purchase_year', DB::raw('count(*) as purchase_count')) ->whereIn('purchase_year', $purchaseYears) ->groupBy('purchase_yea ... -
这是一个缓冲问题。 .at提供无缓冲的操作http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.at.html#numpy.ufunc.at np.add.at(grid_array, (xidx,yidx,zidx),data) This is a buffering issue. The .at provides unbuffered action http://docs.scipy.org/doc/numpy/referenc ...
-
这应该快得多: bigPattern <- paste('(\\b',city[,1],'\\b)',collapse='|',sep='') txt$city <- sapply(regmatches(txt$txt,gregexpr(bigPattern,txt$txt)),FUN=function(x) ifelse(length(x) == 0,'NONE',paste(unique(x),collapse='_'))) 说明: 在第一行中,我们构建了一个匹配所有城市的大型正则表达式,例如: (\ ...