Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

By : Ramon Bernat
Date : September 17 2020, 12:00 AM
Since all the inputs are clearly visible to the compiler at build time, the compiler will simply generate machine codes similar to the one below:
code :
``````A[0] = 3.0f;
A[1] = 5.0f;
A[2] = 7.0f;
A[3] = 9.0f;
``````
``````void myFunc_c(float *pA, float *pB, uint32_t count)
{
if (count == 0) return;

do {
*pA++ += *pB++;
} while (--count);
}

void myFunc_neon(float *pA, float *pB, uint32_t count)
{
float32x4_t a, b;

count >>= 2;
if (count == 0) return;

do {
a = vld1q_f32(pA);
b = vld1q_f32(pB);

vst1q_f32(pA, a);

pA += 4;
pB += 4;

} while (--count);
}
``````

Share :

By : MoonB
Date : March 29 2020, 07:55 AM
I hope this helps . There is good information to be found at ARM's Information Center. The reference is for the assembly instructions, but the names are very similar to the intrinsics. Although if you are going to use NEON, you'll get better performance by just skipping straight to assembly. It's even easier to write than using intrinsics.
To summarize, pairwise addition adds pairs of elements in the same vector, then concatenates the results into a single vector. An illustration (I use 4-element vectors for ease of drawing):
code :
``````vector 'a'   vector 'b'
+-+-+-+-+    +-+-+-+-+
|0|1|2|3|    |4|5|6|7|
+-+-+-+-+    +-+-+-+-+
\+/ \+/      \+/ \+/
1   5        9   13
\   \      /   /
+-+-+-+--+
|1|5|9|13|  result
+-+-+-+--+
``````
``````+-+-+-+--+
|4|6|8|10|
+-+-+-+--+
``````

By : Pido Ayala
Date : March 29 2020, 07:55 AM
To fix the issue you can do There is a sizable amount of overhead when establishing threads. That said, if your sample data set is too small, the amount of time spent spinning up and tearing down the threads will be greater than the actual running time performance of your code.
Let's look at it subjectively. You have an array that contains only 200 elements. Your method's runtime is O(nm), where n is the row size, and m is the column size.
code :
``````The total sum calculated by sequential program is: -570429863
The total time taken by sequential program is: 3369190200
The total sum calculated by multi threaded program is: -570429863
The total time taken by multi threaded program is: 934624554
``````

## Why addition using bitwise operators in this code very slower than arithmetic addition

By : Manpreet Singh
Date : March 29 2020, 07:55 AM
hope this fix your issue Integer arithmetic is performed in hardware typically in a very small number of clock cycles.
You will not be able to get close to this performance in software. Your implementation using bitwise operations involves a function call and a loop. The bitwise operations that you perform typically cost similar numbers of clock cycles as arithmetic.

## why is this simple C++ addition 6 times slower than the equivalent Java?

By : neha
Date : March 29 2020, 07:55 AM
like below fixes the issue hello stackoverflow users, this is my first question asked, so if there are any errors in my way of expressing it, please point it out, thank you , On Linux/Debian/Sid/x86-64, using OpenJDK 7 with
code :
``````// file test.java
class Test {
public static void main(String[] args) {
long start = System.nanoTime();
long total = 0;
for (int i = 0; i < 2147483647; i++) {
total += i;
}
System.out.println(total);
System.out.println(System.nanoTime() - start);
}
}
``````
``````   // file test.cc
#include <iostream>
#include <chrono>

int main (int argc, char**argv) {
using namespace std;
auto start = chrono::high_resolution_clock::now();
long long total = 0;
for (int i = 0; i < 2147483647; i++)
{
total += i;
}
cout << total << endl;
auto finish = chrono::high_resolution_clock::now();
cout << chrono::duration_cast<chrono::nanoseconds>(finish - start).count()
<< endl;
}
``````
``````javac test.java
java Test
``````
``````2305843005992468481
774937152
``````
``````g++ -O2 -std=c++11 test.cc -o test-gcc
``````
``````2305843005992468481
40291
``````
``````2305843005992468481
5208949116
``````
``````    .globl  main
.type   main, @function
main:
.LFB1530:
.cfi_startproc
pushq   %rbx    #
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
call    _ZNSt6chrono3_V212system_clock3nowEv    #
movabsq \$2305843005992468481, %rsi  #,
movl    \$_ZSt4cout, %edi    #,
movq    %rax, %rbx  #, start
call    _ZNSo9_M_insertIxEERSoT_    #
movq    %rax, %rdi  # D.35007,
call    _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_  #
call    _ZNSt6chrono3_V212system_clock3nowEv    #
subq    %rbx, %rax  # start, D.35008
movl    \$_ZSt4cout, %edi    #,
movq    %rax, %rsi  # D.35008, D.35008
call    _ZNSo9_M_insertIlEERSoT_    #
movq    %rax, %rdi  # D.35007,
call    _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_  #
xorl    %eax, %eax  #
popq    %rbx    #
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE1530:
.size   main, .-main
``````

## Addition of GROUP BY to simple query makes it 1000 slower

By : user2316025
Date : March 29 2020, 07:55 AM
hope this fix your issue The EXPLAIN for the first query shows that it does a table-scan (type=ALL) of 300K rows from employees, and for each one, does a partial primary key (type=ref) lookup to 1 row (estimated) in salaries.
code :
``````mysql> explain SELECT * FROM employees
INNER JOIN salaries ON employees.emp_no = salaries.emp_no;
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+-------+
| id | select_type | table     | type | possible_keys | key     | key_len | ref                        | rows   | Extra |
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+-------+
|  1 | SIMPLE      | employees | ALL  | PRIMARY       | NULL    | NULL    | NULL                       | 299113 | NULL  |
|  1 | SIMPLE      | salaries  | ref  | PRIMARY       | PRIMARY | 4       | employees.employees.emp_no |      1 | NULL  |
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+-------+
``````
``````mysql> EXPLAIN SELECT employees.gender, AVG(salary) FROM employees
INNER JOIN salaries ON employees.emp_no = salaries.emp_no
GROUP BY employees.gender;
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+---------------------------------+
| id | select_type | table     | type | possible_keys | key     | key_len | ref                        | rows   | Extra                           |
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+---------------------------------+
|  1 | SIMPLE      | employees | ALL  | PRIMARY       | NULL    | NULL    | NULL                       | 299113 | Using temporary; Using filesort |
|  1 | SIMPLE      | salaries  | ref  | PRIMARY       | PRIMARY | 4       | employees.employees.emp_no |      1 | NULL                            |
+----+-------------+-----------+------+---------------+---------+---------+----------------------------+--------+---------------------------------+
``````
``````mysql> alter table employees add index (gender, emp_no);
``````
``````mysql> EXPLAIN SELECT employees.gender, AVG(salary) FROM employees
INNER JOIN salaries ON employees.emp_no = salaries.emp_no
GROUP BY employees.gender;
+----+-------------+-----------+-------+----------------+---------+---------+----------------------------+--------+-------------+
| id | select_type | table     | type  | possible_keys  | key     | key_len | ref                        | rows   | Extra       |
+----+-------------+-----------+-------+----------------+---------+---------+----------------------------+--------+-------------+
|  1 | SIMPLE      | employees | index | PRIMARY,gender | gender  | 5       | NULL                       | 299113 | Using index |
|  1 | SIMPLE      | salaries  | ref   | PRIMARY        | PRIMARY | 4       | employees.employees.emp_no |      1 | NULL        |
+----+-------------+-----------+-------+----------------+---------+---------+----------------------------+--------+-------------+
``````
``````+--------+-------------+
| gender | AVG(salary) |
+--------+-------------+
| M      |  63838.1769 |
| F      |  63769.6032 |
+--------+-------------+
2 rows in set (1.06 sec)
``````