parmusingh / c-vs-tensorflow Goto Github PK
View Code? Open in Web Editor NEWThis repository is linked to this video : https://www.youtube.com/watch?v=i2LZBnPCxsU
This repository is linked to this video : https://www.youtube.com/watch?v=i2LZBnPCxsU
I tried to improve code for TensorFlow (~17mins) and saw that this code improved performance for me:
import numpy as np
import time
import os
inputs = [331, 884, 254,..]
with tf.Graph().as_default():
inputs = tf.Variable(inputs, dtype=np.float32)
encrypt = (tf.sqrt(inputs) + 523) / 5.3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print('Starting')
t1 = time.time()
for I in range(1000000):
encrypted_data = []
encrypted_data.extend(encrypt.eval())
print(I)
print('completed in : {}s'.format(time.time() - t1))
Torch gave me even better performance though (~15mins):
import time
import os
inputs = [331, 884, 254,...]
inputs = torch.tensor(inputs, dtype=torch.float32)
in_ = inputs.to('cuda:0') # comment this if you don't have GPU support
encrypt = lambda x: (torch.sqrt(x) + 523) / 5.3
print('Starting')
t1 = time.time()
for I in range(1000000):
encrypted_data = []
encrypted_data.extend(encrypt(in_).tolist())
print(I, " ")
print('completed in : {}s'.format(time.time() - t1))
C++ code gave me (~24mins)
After doing this though, I thought I gave advantage of vectorization to TensorFlow and PyTorch. So I, updated C++ code:
#include<math.h>
#include<time.h>
using namespace std;
static inline float encrypt (float x) { return (sqrt(x) + 523) / 5.3; }
int main(){
vector<float> inputs {331, 884, 254,...};
clock_t start;
cout<<"Starting\n";
start = clock();
for(int I = 0; I<1000000; I++){
vector<float> encryptedData(10000);
transform(inputs.begin(), inputs.end(), encryptedData.begin(), encrypt);
cout<<I<<endl;
}
cout<<"Time "<<((float)clock() - (float)start)/CLOCKS_PER_SEC;
return 0;
}
This code gave even tough competition (~14mins) to TF and Torch.
Code optimization is much important to work on as we can never know of all the functions/algorithms/methods in a certain framework or language that can help us improve the performance 10 folds.
CPU: i5 5th gen
GPU: Nvidia GTX 940m 2GB
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.