473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calculating upload speed?

HaLo2FrEeEk
404 256MB
I'm making a quick little ftp uploader as a test and I'm trying to track upload speed. I'm using a loop to write 2048 bytes at a time to the ftp stream, so my logic was to run the loop a predefined number of times and count how long it took to do that number of loops. I'm running the loop 32 times, so I'm uploading 64 kilobytes, then I calculate how many milliseconds it took to upload that amount. I'm just stuck at what to do next. Let's say, for example, that it takes me 250 milliseconds to upload 64 kilobytes (an unrealistic number, but a simple one), I know then that 1/16th of a megabytes takes me 1/4th of a second to upload. So since 1000/250 = 4 (1000 being the number of milliseconds in a second), I would take that 4 and multiply it by 64, the number of bytes I'm uploading per calculation to get 256 Kbps.

I dunno if this is right though...because my program is returning values like 900 for the number of milliseconds per loop. Here is the code I'm using to time everything:

Expand|Select|Wrap|Line Numbers
  1. Stream strm = ftp.GetRequestStream();
  2. contentLen = fs.Read(buff, 0, buffLength);
  3. totalUploaded += contentLen;
  4. DateTime startTime = DateTime.Now;
  5. DateTime endTime;
  6. TimeSpan duration;
  7. while (contentLen != 0)
  8. {
  9.     if (count == 32)
  10.     {
  11.         endTime = DateTime.Now;
  12.         count = 0;
  13.         duration = endTime - startTime;
  14.         double inASec = (double)1000 / (double)duration.Milliseconds;
  15.         uploadSpeed = Math.Round((double)64 * inASec, 2);
  16.         startTime = DateTime.Now;
  17.     }
  18.     strm.Write(buff, 0, contentLen);
  19.     contentLen = fs.Read(buff, 0, buffLength);
  20.     percentDone = Math.Round((totalUploaded / finfo.Length) * 100, 2);
  21.     textBox1.Text = "Uploaded " + totalUploaded + "/" + finfo.Length + " bytes  -  (" + percentDone + "%, " + uploadSpeed + "Kbps)";
  22.     totalUploaded += contentLen;
  23.     progressBar1.PerformStep();
  24.     count++;
  25.     Application.DoEvents();
  26. }
So I basically set my start time, run the loop 32 times then set my stop time. Reset my count to 0, take a timespan duration and get the milliseconds, do my calculations, then reset the start time again.

Is this a good way to do it?
Feb 13 '10 #1
2 8145
You need to consider that ISP speed is kilo bits per second and not kilo bytes per second. So what is 64 kilobytes for you is actually 64 kilobits. Now dividing 900 / 8 = 112.5 kilo bytes per second and that is pretty much achievable. :)
Feb 16 '10 #2
HaLo2FrEeEk
404 256MB
I want to report the kilobyes per second. I just used thed math above and it ended up working great, I get about 150kbps, but it only updates once every 16 loops, so once every 32 kilobytes. I guess the loop is too fast for one duration, and I can't figure out how to use ticks. I'd like to have it update the speed once per loop, like the percent.
Feb 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Serdar C. | last post by:
i am trying to write a program to control upload and download speeds over specific ports like i have 128kbit download and 64kbit upload speed total.. i want to let port xxxx to use maximum amount...
6
by: Bruno Piovan | last post by:
Hello, does anyone know how can I measure the upload speed with asp.net?? I would like to have button on a form and when the user clicks this button, it will show what is the upload speed. ...
40
by: kavi | last post by:
Hello friends, Could any one tell the way of calculating the speed of c program execution?
2
by: Mike Kober | last post by:
I am having issues with the File Upload control for sending files to the server via HTTP. The speed of the upload is often between 20kbs and 40kbs. If I use the LAN at work to the server, it...
4
by: halimunan | last post by:
Hello all, I have a question, how do i measure the download/upload speed... as if download rate, upload rate or kbps transfer rate. i want to do my own windows application using C# to measure the...
10
by: Devang | last post by:
Hello, I am using php script to upload file. some times if file size is too big(1GB) it takes too much time to upload. Can someone suggest me the way to increase upload speed. thanks
14
by: BigZero | last post by:
Hello, can nay body tell me how upload works? "well the code that i m using works fine with me i mean that the file uploadin is working but i m unable to find how it internal it works"? when...
2
dlite922
by: dlite922 | last post by:
I have an intranet LAMP server and I use PHP to upload files. It is of course faster to download the same file than to upload it. I understand ISPs throttle their network for download speed, than...
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.