我需要找到两个函数执行相同操作但用不同算法编写的时间.我需要找到两者中最快的
这是我的代码片段
Stopwatch sw = new Stopwatch();
sw.Start();
Console.WriteLine(sample.palindrome()); // algorithm 1
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);//tried sw.elapsed and sw.elapsedticks
sw.Reset(); //tried with and without reset
sw.Start();
Console.WriteLine(sample.isPalindrome()); //algorithm 2
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Run Code Online (Sandbox Code Playgroud)
从技术上讲,这应该给两个算法花费的时间.这使得算法2更快.但是如果我交换两个函数的调用,它会给出不同的时间.就像我先调用algorithm2而第二次调用algorithm1一样,它表示algorithm1更快.
我不知道我做错了什么.
我正在尝试将事件(addeventlistner)添加到附加有 d3 的多个元素。但是,当我单击 时,它不会触发附加的“警报”。有趣的是,这适用于<div>
我手动添加的内容。有人可以摆脱吗对此有何看法?
d3.csv("output1.csv",function(data){
var width = 700,
height = 600;
d3.select('body').selectAll("div")
.data(data)
.enter()
.append("div")
.style("width",30)
.style('height',30)
.style("background-color",function(d){
return d.color;
})
var divs = document.getElementsByTagName("div") // this returns array of div elements
function show(){
alert("ya")
}
for (var i = 0; i < divs.length; i++) {
divs[i].addEventListener('click',function(){
alert("yaho")
})
}
})
Run Code Online (Sandbox Code Playgroud) <asp:Chart ID="chartSellThru" runat="server" Height="400px" Width="1200px" >
<Series>
<asp:Series Name="ActualsQTD">
</asp:Series>
<asp:Series Name="ForecastQTD">
</asp:Series>
<asp:Series Name="QTDRatio" ChartType="Line">
</asp:Series>
<asp:Series Name="TargetAttain" ChartType="Line">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="SellThruChartArea">
</asp:ChartArea>
</ChartAreas>
chartSellThru.Series["ActualsQTD"].XValueMember = "ProductGroup";
chartSellThru.Series["ActualsQTD"].YValueMembers = "ActualsQTD";
Run Code Online (Sandbox Code Playgroud)
我在default.aspx页面上写了上面的代码行,最后两行代码写在default.aspx.cs页面中.数据绑定到图表.
如何编写折线图的代码.确保从database.how绑定值以将值从sql server绑定到折线图.
这是我获取带有扩展名的Uploaded Filename和仅获取扩展名的语法
$name = Input::file('photo')->getClientOriginalName();
$extension = Input::file('photo')->getClientOriginalExtension();
Run Code Online (Sandbox Code Playgroud)
如果我上传一个名为的文件,那么file.jpg
我会得到
$name = file.jpg
$extension = jpg
Run Code Online (Sandbox Code Playgroud)
是否有任何预定义的方式来获取文件名,即file
不使用任何字符串替换.如果不善意建议一种方法来实现str替换或任何其他方式.
这两种方法之间的确切区别是什么?何时使用"params"以及何时使用数组参数?回复将不胜感激.
// passing array to a method
class Program
{
static void printarray(int[] newarray)
{
int i,sum=0;
Console.Write("\n\nYou entered:\t");
for (i = 0; i < 4; i++)
{
Console.Write("{0}\t", newarray[i]);
sum = sum + newarray[i];
}
Console.Write("\n\nAnd sum of all value is:\t{0}", sum);
Console.ReadLine();
}
static void Main(string[] args)
{
int[] arr = new int[4];
int i;
for (i = 0; i < 4; i++)
{
Console.Write("Enter number:\t");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
// passing array as argument
Program.printarray(arr);
}
} …
Run Code Online (Sandbox Code Playgroud) 如果字符串是这样声明的,那么效果很好
String str="179,206";
String [] numbers = str.split(",");
int[] ints = new int[numbers.length];
for(int i = 0;i < numbers.length;i++)
{
ints[i] = Integer.parseInt(numbers[i]);
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码读取相同的字符串fromm com port
serialPort.openPort();//Open serial port
serialPort.setParams(9600, 8, 1, 0);//Set params.
byte[] buffer = serialPort.readBytes(8);//Read 8 bytes from serial port
String str = new String(buffer);
Run Code Online (Sandbox Code Playgroud)
然后使用前面的代码转换为整数.然后它在线程"main"中给出以下错误Exception
java.lang.NumberFormatException
:对于输入字符串:"179",在java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
在java.lang.Integer.parseInt(Integer.java:481)
在java.lang.Integer.parseInt(Integer.java:527)
在simpleread.SimpleRead.main(SimpleRead.java:44)
我有21行的网格.我的要求是设置一些行背景颜色是浅绿色(如1,5,13行)这是可能实现的.
$("#gridSellIn")
.kendoGrid({
width: 1500,
dataSource: data.d,
resizable: true,
selectable: true,
rowTemplate: kendo.template($("#SellInrowTemplate").html()),
height: 500,
columns: [
{ title: 'RevProduct Name', field: 'ProductName', width: '22%', sortable: true },
{ title: 'Actuals', field: 'Actual', width: '8%', sortable: true },
]
});
Run Code Online (Sandbox Code Playgroud)