Comparing between short and byte operations

Hi, all!
I want to optimize performance of my applet. I have realization of block cipher that work using bytes. But for optimization purpose I rewrite encryption algorithm for short values. In simulator it works 3,5 faster, but when I test it in real card it works 4,5 slower. I use JCOP J2A080 java card.
Has anyone such a problem?
P.S. before optimization I tested different operations in card such : add, shift, xor, and, read/write and for short it works faster.
Code before optimization
    public static void add(byte[] x, short xLen, byte[] y, short yOffset,
               short yLen) {
          short carry = 0, i = 0;
          while (i < yLen) {
               carry += (short) ((x[i] & 0xFF) + (y[i + yOffset] & 0xFF));
               x[i++] = (byte) (carry & 0xFF);
               carry = (short) ((carry >>> 8) & 0xFF);
          while (i < xLen) {
               carry += (short) (x[i] & 0xFF);
               x[i++] = (byte) (carry & 0xFF);
               carry = (short) ((carry >>> 8) & 0xFF);
     private void mainStep(byte[] n1, byte[] key, short keyOffset)
          add(n1, (short) 4, key, keyOffset, (short) 4);
          Util.arrayFillNonAtomic(om, (short) 0, (short) 4, (byte) 0);
          om[0] = sbox[0 + (n1[0] & 0xF)];
          om[0] |= (byte)(bArr[1 + ((n1[0] >>> 4) & 0xF)]<<4);
          om[1]  = (byte)(bArr[2 + (n1[1] & 0xF)]);
          om[1] |= (byte)(bArr[3 + ((n1[1] >>> 4) & 0xF)]<<4);
          om[2]  = (byte)(bArr[4 + (n1[2] & 0xF)]);
          om[2] |= (byte)(bArr[5 + ((n1[2] >>> 4) & 0xF)]<<4);
          om[3]  = (byte)(bArr[6 + (n1[3] & 0xF)]);
          om[3] |= (byte)(bArr[7 + ((n1[3] >>> 4) & 0xF)]<<4);
          n1[3] = (byte) ((om[2] << 3) | ((om[1] & 0xFF) >>> 5));
          n1[2] = (byte) ((om[1] << 3) | ((om[0] & 0xFF) >>> 5));
          n1[1] = (byte) ((om[0] << 3) | ((om[3] & 0xFF) >>> 5));
          n1[0] = (byte) ((om[3] << 3) | ((om[2] & 0xFF) >>> 5));
     }Code after optimization:
     private void mainStep(byte [] bKey, short j)
          short om1 = Util.getShort(bKey, j);
          short om0 = (short)(n_0 + om1);
          //change from add function
          if((((om1 < 0)&& (om0 >= 0)) && (n_0 >= 0))
                    ||
               (((om1 < 0) || (om0 >= 0)) && (n_0 < 0)))
               n_1 += 0x1;
          n_0 = om0;
          n_1 += Util.getShort(bKey, (short) (j+2));
          //and add function
          om0 = (short)(bArr[n_0 & 0xFF]&0xFF);
          om0 |= (short)((bArr[1+ ((n_0 >>> 8) & 0xFF)])<< 8);
          om1 = (short)((bArr[2+ (n_1 & 0xFF)] & 0xFF));
          om1 |= (short)((sbox[3+ ((n_1 >>> 8) & 0xFF)])<< 8);
          n_0 = (short)(( om0 << 11 ) | ((om1 >>> 5) & 0x7FF)) ;
          n_1 = (short)(( om1 << 11 ) | ((om0 >>> 5) & 0x7FF)) ;
     }

From my point of view, simulator is suitable for the logical functionality testing of your application. In order to benchmark your application, you should use an emulator whose configuration is close to your real card.
I used to participated into a smart card benchmark project. The real performance depends on many factors, even the driver for the card reader can affect the application performance. I've never used a simulator to test an application performance so I haven't got any problem like yours. Just some ideas to share with you.
Best regards,
JDL

Similar Messages

  • When to use short and byte

    when do i should really use byte and short anyway?
    let's say i'm writing a MIDlet and i really really want to save up some memory at run time, would it be helpful if i will use short and byte if i dont need large numbers? let's say i only need a maximum representation of 500?
    i know int is commonly used, but is it worth the change?

    I don't know about the Micro Editon VM, but the Java Standard Edition run-time VM has no special instructions for operating using byte primitives as opposed to, say, integer or short primitives, and byte primitives in the VM are stored as ints, I believe. So, chances are your optimizations of these primitives aren't going to save you that much in terms of speed or memory. However, again, my previous comments only apply to the Standard Edition VM [feel free to correct them if I am wrong, as I am not sure if these restrictions have changed since Java v1.3 or not].
    Plus, if your value is going to be a maximum of 500, you need a short because the signed byte primitive will only be valid across the -128 to 127 range.
    -Dok

  • Difference between int and byte

    what is the main difference between int and byte?

    A byte is the format data is stored in memory in past. 8 bits.
    An int is a format likewise you get it as value from the accumulator. For X64 that is Int64.
    For compatibility the "Integer" is kept currently on Int32, the register format from the X86 computers. 
    Older computers likewise the 8088 had an 8 bit Int and therefore that was the same as the byte.
    The 80286 had a 16 bits Integer.
    Success
    Cor

  • Difference between concat and concatenation operator ||

    Hi,
    Most of us may think there is no difference between CONCAT and ||
    By looking in the doc, I can read
    This function is equivalent to the concatenation operator (||). The function is useful when there are spaces in the values to be concatenated. The concatenation operator does not permit spaces.
    <URL:SQL Reference>
    I cannot find a query with a difference, can you?
    SQL> select 'a '||' b',concat('a ',' b') from dual
    'A'||'B' CONCAT('A','B')
    a  b     a  bThanks for feedback
    Laurent

    Thanks APC, this is ok, I understand the platform independance of concat over || . It is also mission impossible to type || on some prehistoric/foreign keyboards/terminals.
    I will write in the docu feedback forum that
    CONCAT: The concatenation operator does not permit spaces.
    concatenation operator: Trailing blanks in character strings are preserved by concatenation
    are not clear, or even contradicting themselves.
    Best regards
    Laurent

  • Compare between Running And No of Applicatioon to be run

    sir
    i   have a batch file contains fixed no of similar service application .exe  files
    after the booting i  have to check weather all the service application are running successfully or not .Compare between the no of running application and fixed no of application..
    If  some are not working .. how to start them automatically...  
      in vb program
    Satyajit Rath

    Hello,
    Please ask in the
    Visual Basic .Net Language forum on MSDN if you want a program.
    If you are creating a script or batch file, I'd ask in
    The Official Scripting Guys Forum!
    Neither place is a good place to go to if you want someone else to do the work for you.
    If you want hints or suggestions to improve what you already have, then the above suggestions are valid.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Difference between finite and continous operations

    Hello All,
      I have a basic question about the finite and continuous AI read VI.
      Please see my attached vi. its function is to read 5 samples and return. The sample clock is a 1KHz external pulse train connected to PFI4. There is also a DAQmx Read Property node to check how many sample available before the DAQmx read vi runs.
      If I choose finite sample mode, the vi completes its execution very fast and the result from DAQmx Read Property node is 5 exactly.
      but if I choose continuous sample mode, the vi takes much longer to complete and the result from DAQmx Read Property node is 512 though I just request 5 samples.
      I just want to make myself more clear about the how DAQmx Read vi runs. my guess is, if you choose continuous mode, then the fetched data won't be available (that means, you only see 0 through the read property node) until certain amount of samples has been acquired, which is 512 in my case. In other word, the continous mode isn't a good way to monitor the data thoughout on the fly.
      Can anybody explain the difference in term of how they perform between two modes?
    thanks
    feilong
    Attachments:
    read finite.vi ‏62 KB

    Hi feilong,
    There is a significant different between finite and continuous mode when you are timing an acquisition.  When you set the timing to finite, it will only acquire a certain number of samples which is set by the number of samples to read.  Continuous mode specifies to acquire data until the task has been stopped.  In continuous mode, when you set the number of samples to read, it just identifies the buffer size in the computer.  This means it specifies the number of samples that are taken at a time into the computer.  There is a PC buffer in you computer that holds a certain number of samples at a time.  However, with continuous once the samples are acquired, it will just go on and acquire the next number of samples until the task has been stopped.  If you go to the NI DAQmx Help (located at Start>>Programs>>National Instruments>>NI-DAQ), you can search from buffer size and there is a document called "How is the Buffer Size Determined" that might be able to explain this concept a little further. 
    At this point, instead of creating your own program, I think it would be better to leverage off of the example programs that National Instruments provides with LabVIEW in order for you to understand the difference in these two modes with analog input and counter measurements.  To get to those example programs, you can go to LabVIEW and go to Tools>>Find Examples and the NI Example Finder will come up.  You will see a folder structure and if you click on Hardware Input and Output>>DAQmx>>Analog Measurements>>Voltage then you will see a lot of examples.  If you click on Acq&Graph Voltage-Ext Clk.vi, this would be a voltage example that uses finite samples.  If you then open up Cont Acq&Graph Voltage-Ext Clk.vi, this is an example that uses continuous mode.  Similarly instead of clicking on Analog Measurements, you can select the folder for Counter Measurements>> Count Digital Events.  There are two examples here as well: Count Digital Events-Buffered-Continuous-Ext Clk.vi uses continuous mode and Count Digital Events-Buffered-Finite-Ext Clk.vi uses finite mode with counters.  Hopefully this information was helpful!
    Regards,
    Vanessa L.
    Applications Engineer
    National Instruments

  • Relation between JVM and different operating system

    What is different between operating system and jvm ?
    how JVM differ from operating system?

    What is different between operating system and jvm ?
    how JVM differ from operating system?That's a really strange question to ask,
    because surely you see the difference
    when you load them.
    For example, most machines run Windows.
    And you then tell Windows to load JVM.
    And you then tell JVM to load a Java program.
    It's like this:
    Hardware -> OS -> JVM -> Java programs
    You can't run any Java programs without first loading a JVM.
    And currently, there are no (popular/successful) JVM that can run without an OS.

  • Difference in WS performance between Search and Retrieve operations?

    All,
    We are currently working on a new repository and planning to use MDM webservices on top of that repository for searching and retrieving the data.
    Now I'm curious about the difference in performance between the Search and the Retrieve operations and also within the Retrieve operation, between the different identification methods (internal ID, auto ID, remote key, unique field and display field).
    Because in the webservices guide is stated that the identification methods are listed in order of best performance, but what are these performance differences between these methods (e.g. a retrieve on internal ID is x times faster than a retrieve on remote key which on his turn is x times faster than a retrieve on display fields which on his turn is x times faster than a search operation on same display field).
    Of course the performance depends on lot of other things as well, but I just want to get a feeling on the performance related to eachother (keeping all other variables that can influence the performance the same!)!
    I hope that any of you has experiences with all possibilities and can share performance measurements between the different operations related to eachother.  Thanks in advance.
    Regards,
    Marcel Herber

    Hi,
    Did you implment Webservices in your site.
    We are also having a similar scenarion where we have to serach a Records in MDM from SAP PI based on the certain criteria. I am concerned about the SAP MDM performance , since we are having heavy amount data being loaded every 30 minutes.
    Please let me know the performace aspects of using Webservices.
    Thanks
    Ganesh Kotti

  • Use always int or short and byte if int is not needed?

    If I have a variable for percentage and if I don't want to use double or float, what type should the variable be? byte? short? int? long?
    Is there a rule? What is a good style?

    The problem is with casting and that it seems that
    Java programmers just use int and double no matter if
    they really need such great values and precision.
    Am I right?You're probably right. I have standardized on int/double, but always use getter/setter methods. In this way I can change the internal representation of variables, for example to save memory space, without affecting the rest of the program. For variables declared in methods I think it's worth using int/double even if you could use "smaller" types. The memory allocated for those variables are reclaimed when the method ends and you don't have to bother much with implicit conversions.

  • Comparism between old and new MacBook Pro

    Hi!
    I have a first generation MacBook Pro1,1 (Core Duo Intel, 2Ghz, 2Gb RAM) and would like to know if I will gain much in oerformance if I buy a new one. Has there been any great performance improvements since my model?
    Thanks!

    Sitara wrote:
    Hi!
    I have a first generation MacBook Pro1,1 (Core Duo Intel, 2Ghz, 2Gb RAM) and would like to know if I will gain much in oerformance if I buy a new one. Has there been any great performance improvements since my model?
    Thanks!
    There are definitely performance gains but how much is a matter of perspective and subjective to the end user, IMHO.
    There's a couple of sites you might wish to visit for more info:
    http://www.barefeats.com (they offer comparisons based on performance via applications, games, between computers, etc.)
    http://www.primatelabs.ca/blog/ (they offer a benchmarking app and posts their results on their blog page)
    HTH.

  • Excise duty caluclate and compare between Amount (JEXQ ) and JEXP

    Dear all,
    We are implementing SAP SD module for cement industry
    So we have special requirement Regarding to Excise Duty
    BED     JEXQ    IS      600 ( with respect to price value)
                JEXP    IS      12% ON MRP.( it should calculate on MRP price)
    For this we have two pricing condition types
    one is normal price
    another one is MRP ( it is statical)
    both should calculate  and compare between both,
    and finally value is not more then 600
    We are using TAXINN  Pricing procedure,
    please suggest me for solution ,
    Regards,
    GANGI

    Hi
    Can u pls chk in your pricing procedure weather the stastics chk box is ticked for the respective condition type.
    If so pls remove and try again.
    Vijay

  • What si the difference between crete and create insert operations.

    Hi
    In ADF 11g,what is the difference between create and createinsert operations.
    if anyone knows plz tell me.Any document about this plz provide me.
    Any help is appreciated.
    Sailaja.

    Hi,
    CreateInsert: Creates a new row that becomes the current row, and inserts the
    new blank row into the data source.
    Create: Creates a new row that becomes the current row, but does not insert it.
    --> normaly you would use createinsert
    Doc you can find here (search for Createinsert): http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974.pdf
    br
    Peter

  • Performance problems between dev and prod

    I run the same query with identical data and indexes, but one system takes a 0.01 seconds to run while the production system takes 1.0 seconds to run. TKprof for dev is:
    Rows Row Source Operation
    1 TABLE ACCESS BY INDEX ROWID VAP_BANDVALUE
    3 NESTED LOOPS
    1 NESTED LOOPS
    41 NESTED LOOPS
    41 NESTED LOOPS
    1 TABLE ACCESS BY INDEX ROWID VAP_PACKAGE
    1 INDEX UNIQUE SCAN SYS_C0032600 (object id 51356)
    41 TABLE ACCESS BY INDEX ROWID VAP_BANDELEMENT
    41 AND-EQUAL
    82 INDEX RANGE SCAN IDX_BE2 (object id 53559)
    41 INDEX RANGE SCAN IDX_BE1 (object id 53558)
    41 TABLE ACCESS BY INDEX ROWID VAP_BAND
    41 INDEX UNIQUE SCAN SYS_C0034599 (object id 53556)
    1 INDEX UNIQUE SCAN SYS_C0032549 (object id 51335)
    1 INDEX RANGE SCAN IDX_BV1 (object id 53557)Tkprof for Prod is :
    Rows Execution Plan
    0 SELECT STATEMENT MODE: ALL_ROWS
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'VAP_BANDVALUE' (TABLE)
    52001 NESTED LOOPS
    26000 NESTED LOOPS
    26000 NESTED LOOPS
    26000 NESTED LOOPS
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'VAP_PACKAGE' (TABLE)
    1 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'SYS_C0018725' (INDEX (UNIQUE))
    26000 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'VAP_BANDELEMENT' (TABLE)
    26000 INDEX MODE: ANALYZED (RANGE SCAN) OF 'IDX_BE2' (INDEX)
    26000 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'VAP_BAND' (TABLE)
    26000 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'SYS_C0030648' (INDEX (UNIQUE))
    26000 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'SYS_C0018674' (INDEX (UNIQUE))
    26000 INDEX MODE: ANALYZED (RANGE SCAN) OF 'IDX_BV1' (INDEX).The row count varies greatly. But it shouldn't as the data is the same.
    Any ideas?

    From DEV you show the Row Source Operations for the query. The column named "Rows" signifies the actual number of rows processed with each step.
    From PROD you show the Execution Plan for the query; that is, tkprof was executed with the EXPLAIN option which generates the execution plan as of the time when tkprof was run. The "Rows" column in the Explain Plan output comes from the PLAN_TABLE.CARDINALITY, which represents an estimate by the CBO for the number of rows [expected to be] processed with each step.
    So, if by <quote>The row count varies greatly</quote> you meant these "Rows" columns outputs then you're are comparing actuals from a database with estimates from another. Get the Row Source Operations from both.
    "Identical data and indexes":
    1. data may be the same, but it is not necessarily stored physically the same way.
    2. Indexes being the same means their definitions are the same; again, physically they are not necessarily identical
    In other words, data in PROD (the way it is stored on disk) may have evolved as a result of discrete deletes/updates/inserts ... in DEV it could be, for example, stored more compact if you took a copy of PROD and moved into DEV. So, the number of blocks for your segments will likely be different between PROD and DEV, the clustering factor for your indexes are likely different, etc ... things which could [and do] influence the CBO. The statistics may be different.
    I guess what I'm saying is ... it is quite hard, if not outright impossible, to get two identical databases/instances/load ... hence, don't expect the executions to be 100% identical, even if you have "identical data and indexes". By all means compare between DEV and PROD (make sure you compare the same thing though) and use the observed differences as an indicator for further investigation ... don't chase the goal of 100% identical behavior.
    Now, by all means look at that query taking 1 second in PROD ... I have only addressed <quote>The row count varies greatly. But it shouldn't as the data is the same.</quote>

  • How to make my applicatio​n programmat​ically switch between English and Russian

    Greetings from Colorado...
    My application needs to be switchable between English and Russian.  Future languages to add are Spanish and Chinese.  The user selects a language
    from a control before starting the program and then the program changes the Captions, Boolean Texts, Graph Labels, and Enum Type Strings to the
    chosen language.  For Russian, this requires a different set of characters.  I have made substantial progress by:
    Control Panels>Region and Language>Keyboards and Languages>Change Keyboards added Russian>Keyboard>Russian on my development
    computer.
    In the LabVIEW.ini file, I added UseUnicode=TRUE (thanks to a suggestion found in this forum)
    Made property nodes for controls and used properties such as Interpret As Unicode (True for Russian, False for English), Text, Font Name, Font Size, etc.
    I have used fonts Arial and Arial CYR for Russian and MS Sans Serif for English
    Set the keyboard for Russian and enter Cyrillic characters into text constants that are set for Arial or Arial CYR font.  Sometimes one works and
    sometimes the other works.  As long as I set the font name in the property node the same way the text went into the text constant, it generally
    works.  I wish I could understand why one works sometimes and the other works other times!
    I have had trouble with the Boolean Text going off-center when changing fonts and languages and it seems that by setting the Lock Text In Center
    property to False and then True again, it seems to work.  Often changing Boolean texts between short and long texts causes some of the long text
    to be non-displayed; I have remedied this by explicitly setting the width of the Boolean text in a property node.
    Often, the Russian text appears as gibberish with strange right-angle characters, :s, =s, and tiny numbers.  I have been able to remedy this on my
    development computer by ensuring that the text constant on the block diagram has the same size as the caption is supposed to have.  This
    is not necessary for normal programming in English, but it seems to help here.  But it doesn't always solve the problem.
    Sometimes the English text appears as Chinese gibberish in an Enum Type selection list or in a graph label.  On my development computer,
    it seems that making the text the last property to change helps here.
    By changing the sequences of assignments to a single property node with a long list of properties, I have been able to make some of these
    controls to switch between languages without gibberish showing up.
    A few hours ago, I had the Russian strings in the Enum Type control working, except that when selecting from the available items, only the first
    word of the Russian string was displayed.  Two of the items start with the same word, so the user can't distinguish them.  
    At that time the English strings were appearing as Chinese gibberish while the list during the selection process displayed in English.  As soon
    as I changed the selection, future attempts to change the selection gave Chinese gibberish during the selection process, too.  But this was only
    a problem in the executable version; the source-code version worked fine.
    In an attempt to get rid of the Chinese gibberish, I made new constants and retyped the items into them.  This worked!  But then, the Russian
    stopped working and gave gibberish angles and tiny numbers, even though I didn't touch any of the code that sets the properties in Russian mode.
    After trying a few sequences of setting the properties for the graph X label on page 2 of my tab control, this label started working correctly for both
    languages.  But the text of that label comes through on page 1 of the tab control, partly obscured by other controls on that page.  After the
    program runs a few more seconds, these shadows disappear.
    Most times I restart LabVIEW, I get an error message saying there was a crash due to fontmgr.cpp, line 7494.  But there actually wasn't a crash.
    My computer has Windows 7 64-bit.  Deployment Computer has Windows 7 32-bit.  LabVIEW version is 8.5.  
    I have probably 50 or 100 more controls and indicators to change to language programmability and figuring out all this stuff for each one is
    terribly time-consuming and there is no assurance that all of them will ever work.  
    At this point, I'm hoping that I am on an entirely wrong path and someone will send me a clue to get me on a path that is more predictable.
    Thanks in advance to all who post ideas!
    Cheers
    Halden 

    Hi All,
    I've made a lot of progress on this translation, but it's been really hard.  There are lots of weird things going on that must be logical because they're in a computer, but I can't figure out what the logic is.  When changing a font on a caption using the front panel, it sometimes changes the font on the caption and sometimes doesn't although the indicator always indicates the new font.  Removing the first character of the unicode font string being sent to the caption seems to help...huh?  Anyway, tabs still can't change language programmatically, and niether can ring controls (some kinds will take the new list of strings, but when selecting, they only display the first word of the string!).  Boolean text can be reprogrammed, but only if the boolean text is set to be the same for both true and false states.  When reprogramming captions on a non-displayed page of a multi-page tab-controlled user interface, the new text appears on the current page until I change pages back and forth.  What a pain!
    Sooo, NI....does LabVIEW 2011 have support for unicode fonts?  Or, is there anything else in the new control style that will support programmatic language changing?
    Halden 

  • Difference between trunc and mod

    hi,
    what is the difference between trunc and mod operator
    can any one explain
    thanks in advance

    If you are going to ask for the difference between every pair of unrelated functions we could be here for some time. What is the difference between UPPER and CEIL? etc
    TRUNC and MOD are both clearly documented in the SQL Reference.

Maybe you are looking for

  • Can't add video to my ipod

    i can't add my videos to my ipod from itunes. itunes reads my videos but when i try and add them to my ipod it say's this ipod can't read these files. i have got the new ipod update and itunes and it still doesnt work. DOES ANYONE KNOW HOW TO GET ROU

  • Everything about the IPOD Classic 160 GB Battery

    Dear All, Just want to know how the battery is connected and placed inside the ipod classic 160GB model, can it be replaced by a user without using a soldering iron.Is it attached with a adhesive ? Kindly discuss. Thanks

  • FTP COMMANDS IN BACK GROUND

    Hi every one, I am using ftp_connect, ftp_command function modules. i want to schedule my program in backround,but this s not working.... RFC DEST used is SAPFTP and also tried SAPFTPA.. no use.. THANKS IN ADVANCE RAVI

  • Blank error message in iphoto?

    Hi Seemingly out of the blue iphoto 11 has taken to having a blank message when I try to send a photo by email. I assume it's an error message. Does anyone have any suggestions please? The message comes up shortly after the animated blue sending bar

  • Photoshop CC does not start up

    Photoshop CC does nog start up. Only the screen with plugins seeking appears and then nothing. What can I do?