|
|
I thought so - sometime I'll have to look at the IL to see why ...
But if you are looking for some real micro optimizations, this may be of use: Writing IL code on Visual Studio[^]
I haven't used it but it looks interesting, and I still believe that a human can produce better machine code than a compiler!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
No, that's wrong. It's a classic case of "measuring time but not looking at what the time was measured of".
The best the remainder solution can hope for, is that the JIT compiler recognizes it and turns it into the equivalent of the bitwise-AND solution, which happens for uint but not int . So at best it is the exact same code running, any differences observed in timing are just timing noise. And sometimes (eg for int ), it's just straight up worse to use the remainder instead of bitwise AND.
|
|
|
|
|
I use this:
public static bool IsOdd(this int value)
{
return (value % 2 == 1);
}
Is it the best method? I don't know, and can't say. Is it the fastest? I don't care. Is that odd? Lemme check...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Well stop using it, -1 % 2 = -1 so it doesn't work for negative inputs, it's a nasty trap.
|
|
|
|
|
So use return (Math.Abs(value%2) == 1) . It's not that nasty.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Sure, now it just throws an exception for int.MinValue . But value % 2 != 0 works.
|
|
|
|
|
You're going to have to test on your own machine.
On mine, 2,000,000,000 iterations of % or bitwise mask with 0x01 can be done in 494 to 499 milliseconds using either operation.
So, how picky do you want to be with a couple thousands of a second across 2 billion operations?
|
|
|
|
|
I won't be that picky. It's more a question of curiosity.
|
|
|
|
|
Hi,
I have a DataTable named dt .
It has 4 columns and 2000 rows. Columns are Code, Department, Part, Status, respectively. In my app, Department can be 4 checkboxes (Electrical, Mechanical, R&D, Industrial Engineering). Part can be checkboxes named North, East, West. Status can be checkboxes named Ended, In Progress.
I have checked Electrical and Mechanical in Department checkboxes, West and North in Part checkboxes, Inprogress in Status checkboxes (it can take any order of checked checkboxes).
I want to remove rows which don't satisfy my conditions (remove based on checkboxes)
What is the best solution?
I think I should create a list for indexes to be removed. But, I don't exactly know how to fill that list correctly based on those check boxes.
Let's clear it. I use Dev Express Spreadsheet in my own project. I deliver the whole spreadsheet into a DataTable. I use those checkboxes (toggle check) as settings in my menu, not in every row. Those are just settings that the user sets before pressing the calculation button.
modified 2-Apr-21 0:12am.
|
|
|
|
|
I think you should scrap the whole thing and rethink your entire UI.
2000 rows, each with a variety of checkboxes?
How do you expect any user to actually use that? Did you even try it past the first page? How long do you think it's going to take to set up all the checkboxes ready to press the "delete" button, check that they have the right ones - and no wrong ones?
I have no idea what exactly you want to do, but I am pretty sure that that isn't the right idea.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Let's clear it. I use Dev Express Spreadsheet in my own project. I deliver the whole spreadsheet into a DataTable. I use those checkboxes (toggle check) as settings in my menu, not in every row. Those are just settings that the user sets before pressing the calculation button.
|
|
|
|
|
So presumably you and/or your users will never ever grow the business to the size where there will be 20,000 much less 20,000,000 entries in that list.
Typically what these solutions are when they do not support 20 million rows (or more) is that the check boxes only apply to the currently viewable page. If the you and your users want to go through 500 pages checking boxes then they can do it. But then one doesn't need to worry about how long it the UI will take to display, update and manage large numbers of rows. (And I am not suggesting that solution just noting it.)
|
|
|
|
|
I have done some solutions but it works correctly when I check just one checkbox. When I use more than one checkboxes for each column's contents, it deletes some rows unintentionally.
|
|
|
|
|
My code may seem complicated but I try to give you some necessary parts. In this code, I delete rows based on duplicate contents of column E, from/to dates and toggle checkboxes checked:
int LastRow = my_table3.Rows.Count;
my_table3.Columns.Add("تاریخ");
my_table3.Rows[0][35] = "تاریخ";
for (int i = 1; i < LastRow; i++)
{
my_table3.Rows[i][35] = string.Join("/", my_table3.Rows[i][19], my_table3.Rows[i][20]);
}
var check_box = new List<string>();
foreach (BarItem c in ribbonControl1.Items)
{
if (c is BarToggleSwitchItem tg)
{
if (tg.Checked)
{
check_box.Add(tg.Description);
}
}
}
var valuesSeen = new HashSet<string>();
var duplicateRows = new List<int>();
column_select.EditValue = "E";
string selcolumn = (string)column_select.EditValue;
int column_index = worksheet.Columns[selcolumn].Index;
for (int i = 0; i < LastRow; i++)
{
string cellValue = my_table3.Rows[i][column_index].ToString();
if (valuesSeen.Add(cellValue) == false)
{
duplicateRows.Add(i);
}
}
for (int i = duplicateRows.Count - 1; i >= 0; i--)
{
int index = duplicateRows[i];
my_table3.Rows[index].Delete();
my_table3.AcceptChanges();
}
LastRow = my_table3.Rows.Count;
var ToDelete = new List<int>();
for (int i = 1; i < LastRow; i++)
{
string one = FromDate.EditValue.ToString();
string two = ToDate.EditValue.ToString();
string three = my_table3.Rows[i][35].ToString();
DateTime dOne = GetDate(one);
DateTime dTwo = GetDate(two);
DateTime dThree = GetDate(three);
bool answer = dThree >= dOne && dThree <= dTwo;
string cellValue = my_table3.Rows[i][10].ToString();
string cellvalue2 = my_table3.Rows[i][9].ToString();
for (int k = 0; k < check_box.Count; k++)
{
if (cellValue != "خاتمه یافته" || cellvalue2 != "تعمیراتی" || answer == false || my_table3.Rows[i][14].ToString() != check_box[k].ToString())
{
ToDelete.Add(i);
}
}
}
for (int i = ToDelete.Count - 1; i >= 0; i--)
{
int index = ToDelete[i];
my_table3.Rows[index].Delete();
my_table3.AcceptChanges();
}
modified 2-Apr-21 1:39am.
|
|
|
|
|
Design your form with the checkboxes set up as filters, allow the users to select any filter elements validating that a minimum are checked - 2000 row is ridiculous.
Have the data in the supporting .cs ready to be filtered but not displayed.
Add a go button to apply the filter, filter the underlying data into a list and bind the list to the UI grid and disable the go button.
Rinse and repeat if the user changes the filter conditions (when a checkbox in the filter is changed clear the list and enable the go button).
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Let's clear it. I use Dev Express Spreadsheet in my own project. I deliver the whole spreadsheet into a DataTable. I use those checkboxes (toggle check) as settings in my menu, not in every row. Those are just settings that the user sets before pressing the calculation button.
|
|
|
|
|
Your menu and checkbox structure is fine - your treatment of the datatable is not.
Create a new datatable (or list) to store the rows to be displayed.
Loop each record in the source datatable (2k rows from the database)
check each of the criteria on the row
If the row passes the filter then add it to the display datatable or list.
DO NOT DELETE THE DATA FROM THE SOURCE DATATABLE or you need to go back to the database for each filter.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
You should be using radio buttons, not checkboxes; your options are mutually exclusive. Which also implies fewer fields. You have architectural issues.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The user may need to filter West and East parts, for example. Thus, I have to provide toggle checkboxes.
|
|
|
|
|
In that case, use checkboxes.
So far, it would seem easier to create a new datatable by "filtering" the original; instead of compacting the original.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi all, I use a partial view in my net core MVC Web project ( personal project not work ) which receives a Model ViewButtonText
public class ViewButtonText
{
public string ButtonText { get; set; }
}
and the partial view is
@model Commands.Models.ViewButtonText
<input type="submit" name="submit" value=@Model.ButtonText>
<input type="submit" name="submit" value="Cancel" />
All works as expected until I set ButtonText to a value which has a space in it e.g. "My Button" which results in the text on the button only showing the first word - any idea why guys ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
@model Commands.Models.ViewButtonText
<input type="submit" name="submit" value="@Model.ButtonText">
<input type="submit" name="submit" value="Cancel" />
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
Thanks Matthew
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Hi,
Could you help with all possible ways of autoconnection of shapes dropped in WPS canvas?
We are assuming that:
1. Shapes have connectors/adorners
2. Shapes have in same layer
3. Second shape dragged from shapes library and brought close to first shape.
4. Next - happens autonnection of close to each other connectors.
The visual (only) reference can be seen (from 8m11sec) GERU Tutorial: Logic Flow & Email Messages - YouTube[^]
The main problem of using the option of constant comparison/calculation of connectors' distance will be done during the move of shapes.
And it will load the CPU as technically each/any movement of any shape (there can be dozen) in canvas will be calculated then heavily loading the CPU=slowing down the app...
Are there different ways or tips/tricks of doing it?
Ideally some sample of code if feasible?
Thanks a lot!
modified 31-Mar-21 13:35pm.
|
|
|
|