Last active
August 29, 2015 14:26
-
-
Save reza-ryte-club/3c92f3fa1bd3eea679e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require ('fs'); | |
fs.readdir(__dirname, function (err, files) { | |
console.log(files); | |
}); | |
// function readLines(input, func) { | |
// var remaining = ''; | |
// input.on('data', function(data) { | |
// remaining += data; | |
// var index = remaining.indexOf('\n'); | |
// while (index > -1) { | |
// var line = remaining.substring(0, index); | |
// remaining = remaining.substring(index + 1); | |
// func(line); | |
// index = remaining.indexOf('\n'); | |
// } | |
// }); | |
// input.on('end', function() { | |
// if (remaining.length > 0) { | |
// func(remaining); | |
// } | |
// }); | |
// } | |
// function func(data) { | |
// console.log('Line: ' + data); | |
// } | |
// var input = fs.createReadStream('sample.log'); | |
// var str = readLines(input, func); | |
// console.log(typeof(str)); | |
// //var count1 = (str.match(/is/g) || []).length; | |
// var temp = "This is is a string."; | |
// // the g in the regular expression says to search the whole string | |
// // rather than just find the first occurrence | |
// var count = (temp.match(/is/g) || []).length; | |
// console.log(count); | |
var file = fs.readFileSync("sample.log", "utf8"); | |
//console.log(file); | |
// /api/users/ | |
console.log("Synopsis:\n"); | |
console.log("URL\t\t\t\t\t\t Number of time being called\n"); | |
// /api/users/{user_id}/count_pending_messages" | |
var count2 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/count_pending_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g) || []).length; | |
console.log("GET /api/users/{user_id}/count_pending_messages\t"+count2); | |
// /api/users/{user_id}/get_messages; | |
var count3 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_messages/g) || []).length; | |
console.log("GET /api/users/{user_id}/get_messages\t\t"+count3); | |
// /api/users/{user_id}/get_friends_progress; | |
var count4 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_progress/g) || []).length; | |
console.log("GET /api/users/{user_id}/get_friends_progress\t"+count4); | |
// /api/users/{user_id}/get_friends_score; | |
var count5 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_score/g) || []).length; | |
console.log("GET /api/users/{user_id}/get_friends_score\t"+count5); | |
//GET /api/users/{user_id}; | |
var count6 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\s/g) || []).length; | |
console.log("GET /api/users\t\t\t\t\t"+count6); | |
//POST /api/users/{user_id}; | |
var count7 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=POST\spath=\/api\/users\/\w+\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g) || []).length; | |
console.log("POST /api/users\t\t\t\t\t"+count7); | |
console.log("\nTotal number of url call :",count2+count3+count4+count5+count6+count7); | |
//var count8 = (file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/count_pending_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g) || []).length; | |
//console.log(count8); | |
// requesttime2 = []; | |
// for(var i=0;i<count2;i++){ | |
// var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/count_pending_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('connect=')[1]; | |
// var sPosition = s_id.indexOf(' '); | |
// if(sPosition != -1) { | |
// s_id = s_id.substring(0,sPosition); | |
// } | |
// s_id = s_id.replace(/\D/g,''); | |
// // console.log(s_id+ " "+(i+1)); | |
// var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/count_pending_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var mPosition = m_id.indexOf(' '); | |
// if(mPosition != -1) { | |
// m_id = m_id.substring(0,mPosition); | |
// } | |
// m_id = m_id.replace(/\D/g,''); | |
// //console.log(m_id+ " "+(i+1)); | |
// requesttime2.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
// console.log(m_id+" "+s_id +" "+(i+1)); | |
// } | |
// console.log("Mean response time for GET /api/users/{user_id}/count_pending_messages : "+(eval(requesttime2.join('+')))/count2); | |
// requesttime3 = []; | |
// for(var i=0;i<count3;i++){ | |
// var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('connect=')[1]; | |
// var sPosition = s_id.indexOf(' '); | |
// if(sPosition != -1) { | |
// s_id = s_id.substring(0,sPosition); | |
// } | |
// s_id = s_id.replace(/\D/g,''); | |
// // console.log(s_id+ " "+(i+1)); | |
// var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_messages\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var mPosition = m_id.indexOf(' '); | |
// if(mPosition != -1) { | |
// m_id = m_id.substring(0,mPosition); | |
// } | |
// m_id = m_id.replace(/\D/g,''); | |
// //console.log(m_id+ " "+(i+1)); | |
// requesttime3.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
// console.log(m_id+" "+s_id +" "+requesttime3[i]+" "+(i+1)); | |
// } | |
// console.log("Mean response time for GET /api/users/{user_id}/get_messages : "+((eval(requesttime3.join('+')))/count3)); | |
// requesttime4 = []; | |
// for(var i=0;i<count4;i++){ | |
// var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_progress\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('connect=')[1]; | |
// var sPosition = s_id.indexOf(' '); | |
// if(sPosition != -1) { | |
// s_id = s_id.substring(0,sPosition); | |
// } | |
// s_id = s_id.replace(/\D/g,''); | |
// // console.log(s_id+ " "+(i+1)); | |
// var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_progress\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var mPosition = m_id.indexOf(' '); | |
// if(mPosition != -1) { | |
// m_id = m_id.substring(0,mPosition); | |
// } | |
// m_id = m_id.replace(/\D/g,''); | |
// //console.log(m_id+ " "+(i+1)); | |
// requesttime4.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
// console.log(m_id+" "+s_id +" "+requesttime4[i]+" "+(i+1)); | |
// } | |
// console.log("Mean response time for GET /api/users/{user_id}/get_friends_progress : "+((eval(requesttime4.join('+')))/count4)); | |
requesttime5 = []; | |
for(var i=0;i<count5;i++){ | |
var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_score\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('connect=')[1]; | |
var sPosition = s_id.indexOf(' '); | |
if(sPosition != -1) { | |
s_id = s_id.substring(0,sPosition); | |
} | |
s_id = s_id.replace(/\D/g,''); | |
// console.log(s_id+ " "+(i+1)); | |
var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\/get_friends_score\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
var mPosition = m_id.indexOf(' '); | |
if(mPosition != -1) { | |
m_id = m_id.substring(0,mPosition); | |
} | |
m_id = m_id.replace(/\D/g,''); | |
//console.log(m_id+ " "+(i+1)); | |
requesttime5.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
console.log(m_id+" "+s_id +" "+requesttime5[i]+" "+(i+1)); | |
} | |
console.log("Mean response time for GET /api/users/{user_id}/get_friends_score : "+((eval(requesttime5.join('+')))/count5)); | |
if(count5%2==0){ | |
console.log("Median = "+(requesttime5[Math.floor(count5/2)]+requesttime5[Math.floor(count5/2)-1])/2); | |
} | |
else{ | |
console.log("Median = "+requesttime5[Math.floor(count5/2)]); | |
} | |
// requesttime6 = []; | |
// for(var i=0;i<count6;i++){ | |
// var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('connect=')[1]; | |
// var sPosition = s_id.indexOf(' '); | |
// if(sPosition != -1) { | |
// s_id = s_id.substring(0,sPosition); | |
// } | |
// s_id = s_id.replace(/\D/g,''); | |
// // console.log(s_id+ " "+(i+1)); | |
// var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=GET\spath=\/api\/users\/\w+\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var mPosition = m_id.indexOf(' '); | |
// if(mPosition != -1) { | |
// m_id = m_id.substring(0,mPosition); | |
// } | |
// m_id = m_id.replace(/\D/g,''); | |
// //console.log(m_id+ " "+(i+1)); | |
// requesttime6.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
// console.log(m_id+" "+s_id +" "+requesttime6[i]+" "+(i+1)); | |
// } | |
// console.log("Mean response time for GET /api/users/{user_id} : "+((eval(requesttime6.join('+')))/count6)); | |
// if(count6%2==0){ | |
// console.log("Median = "+(requesttime6[Math.floor(count6/2)]+requesttime6[Math.floor(count6/2)-1])/2); | |
// } | |
// else{ | |
// console.log("Median = "+requesttime6[Math.floor(count6/2)]); | |
// } | |
// requesttime7 = []; | |
// for(var i=0;i<count7;i++){ | |
// var s_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=POST\spath=\/api\/users\/\w+\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var sPosition = s_id.indexOf(' '); | |
// if(sPosition != -1) { | |
// s_id = s_id.substring(0,sPosition); | |
// } | |
// s_id = s_id.replace(/\D/g,''); | |
// // console.log(s_id+ " "+(i+1)); | |
// var m_id = file.match(/\w+-\w+-\w+:\w+:\w+.\w+\+\w+:\w+\s\w+\[\w+\]:\sat=info\smethod=POST\spath=\/api\/users\/\w+\shost=\w+.\w+.\w+\sfwd=\"\w+.\w+.\w+.\w+\"\sdyno=\w+.\w+\sconnect=\w+\sservice=\w+\s/g)[i].split('service=')[1]; | |
// var mPosition = m_id.indexOf(' '); | |
// if(mPosition != -1) { | |
// m_id = m_id.substring(0,mPosition); | |
// } | |
// m_id = m_id.replace(/\D/g,''); | |
// //console.log(m_id+ " "+(i+1)); | |
// requesttime7.push(parseInt(s_id,10)+parseInt(m_id,10)); | |
// console.log(m_id+" "+s_id +" "+requesttime7[i]+" "+(i+1)); | |
// } | |
// console.log("Mean response time for GET /api/users/{user_id}/get_friends_progress : "+((eval(requesttime7.join('+')))/count7)); | |
// if(count7%2==0){ | |
// console.log("Median = "+(requesttime7[Math.floor(count7/2)]+requesttime7[Math.floor(count7/2)-1])/2); | |
// } | |
// else{ | |
// console.log("Median = "+requesttime7[Math.floor(count7/2)]); | |
// } | |
// //Mean of response time | |
// //var str = readLines(file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment