optimization

counter_cache has_many_through sql optimisation, reduce number of sql queries

萝らか妹 提交于 2019-12-30 01:36:11
问题 How I can optimise my SQL queries, to ignore situations like this: Meeting.find(5).users.size => SELECT COUNT(*) FROM ... WHERE ... User.find(123).meetings.size => SELECT COUNT(*) FROm ... WHERE ... I have no idea how to use counter_cache here. Here is my model relation: class Meeting < ActiveRecord::Base has_many :meeting_users has_many :users, :through => meeting_users end class User < ActiveRecord::Base has_many :meeting_users has_many :meetings, :through => meeting_users end class Meeting

explicit copy constructor or implicit parameter by value

孤人 提交于 2019-12-30 00:07:10
问题 I recently read (and unfortunately forgot where), that the best way to write operator= is like this: foo &operator=(foo other) { swap(*this, other); return *this; } instead of this: foo &operator=(const foo &other) { foo copy(other); swap(*this, copy); return *this; } The idea is that if operator= is called with an rvalue, the first version can optimize away construction of a copy. So when called with a rvalue, the first version is faster and when called with an lvalue the two are equivalent.

Fastest 2D convolution or image filter in Python

喜欢而已 提交于 2019-12-29 14:15:19
问题 Several users have asked about the speed or memory consumption of image convolutions in numpy or scipy [1, 2, 3, 4]. From the responses and my experience using Numpy, I believe this may be a major shortcoming of numpy compared to Matlab or IDL. None of the answers so far have addressed the overall question, so here it is: "What is the fastest method for computing a 2D convolution in Python?" Common python modules are fair game: numpy, scipy, and PIL (others?). For the sake of a challenging

The audio volume is zero?

允我心安 提交于 2019-12-29 09:37:09
问题 I have an application with a mute button. I have been stuck on this for 4 and a half hours now, so I am plain desperate. I am trying to have the volume mute when user clicks mute and unmute when user clicks it again. This works fine, except the audio isn't playing. For some reason, Stream_Music is 0? public void mute(View view) { mutebutton = (ImageButton) findViewById(R.id.mutebutton); if ((variableForMute.x % 2) != 0) { //If it's odd UNMUTE Log.v(TAG, "Use this volume to unmute "

SQL — How is DISTINCT so fast without an index?

丶灬走出姿态 提交于 2019-12-29 09:32:51
问题 I have a database with a table called 'links' with 600 million rows in it in SQLite. There are 2 columns in the database - a "src" column and a "dest" column. At present there are no indices. There are a fair number of common values between src and dest, but also a fair number of duplicated rows. The first thing I'm trying to do is remove all the duplicate rows, and then perform some additional processing on the results, however I've been encountering some weird issues. Firstly, SELECT * FROM

Efficient Parsing of XML

北战南征 提交于 2019-12-29 09:32:22
问题 Good day, I'm writing a program in C# .Net to manage products of my store, Following a given link I can retrieve an XML file that contains all the possible products that I can list onto my storefront. The XML structure looks like this : <Product StockCode="103-10440"> <lastUpdated><![CDATA[Fri, 20 May 2016 17:00:03 GMT]]></lastUpdated> <StockCode><![CDATA[103-10440]]></StockCode> <Brand><![CDATA[3COM]]></Brand> <BrandID><![CDATA[14]]></BrandID> <ProdName><![CDATA[BIG FLOW BLOWING JUNCTION

Efficient Parsing of XML

荒凉一梦 提交于 2019-12-29 09:32:07
问题 Good day, I'm writing a program in C# .Net to manage products of my store, Following a given link I can retrieve an XML file that contains all the possible products that I can list onto my storefront. The XML structure looks like this : <Product StockCode="103-10440"> <lastUpdated><![CDATA[Fri, 20 May 2016 17:00:03 GMT]]></lastUpdated> <StockCode><![CDATA[103-10440]]></StockCode> <Brand><![CDATA[3COM]]></Brand> <BrandID><![CDATA[14]]></BrandID> <ProdName><![CDATA[BIG FLOW BLOWING JUNCTION

SQL — How is DISTINCT so fast without an index?

余生长醉 提交于 2019-12-29 09:32:01
问题 I have a database with a table called 'links' with 600 million rows in it in SQLite. There are 2 columns in the database - a "src" column and a "dest" column. At present there are no indices. There are a fair number of common values between src and dest, but also a fair number of duplicated rows. The first thing I'm trying to do is remove all the duplicate rows, and then perform some additional processing on the results, however I've been encountering some weird issues. Firstly, SELECT * FROM

Regex Optimization for large lists

陌路散爱 提交于 2019-12-29 09:21:36
问题 I am comparing two lists of strings to find possible matches. Example: public class Tester { public static void main(String[] args) { List<String> test = new ArrayList<String>(); List<String> test2 = new ArrayList<String>(); test.add("3H0875AAAA0012"); test.add("3H0875AABB0018"); test.add("3H0875AAAC0010"); test2.add("3H0875AA"); for(String s2: test2){ for (String s: test){ if (s.matches(".*" + s2 + ".*")){ System.out.println("Match"); } } } } } Basically for every string in test2 I want to

Regex Optimization for large lists

一笑奈何 提交于 2019-12-29 09:21:35
问题 I am comparing two lists of strings to find possible matches. Example: public class Tester { public static void main(String[] args) { List<String> test = new ArrayList<String>(); List<String> test2 = new ArrayList<String>(); test.add("3H0875AAAA0012"); test.add("3H0875AABB0018"); test.add("3H0875AAAC0010"); test2.add("3H0875AA"); for(String s2: test2){ for (String s: test){ if (s.matches(".*" + s2 + ".*")){ System.out.println("Match"); } } } } } Basically for every string in test2 I want to